Blogger Widgets
  • Sharing Photos using SignalR
  • TFS Extenstion - allows copy work items between projects
  • Displaying jquery progressbar with ajax call on a modal dialog
  • Managing windows services of a server via a website
  • Exploring technologies available to date. TechCipher is one place that any professional would like to visit, either to get an overview or to have better understanding.

Search This Blog

Wednesday 24 August 2011

Formatting date in XSL using .NET standard formatting

Microsoft standard .NET date format can be used in xsl transform which is a key feature provided using msxsl:script Element.

The following snippet demonstrates using .NET "ToShortDateString" inside XSL transform:-


  
  

Above defined method "ToCSharpShortDateString" can be used as follows:-



Now that xsl is ready, lets use this with ASP.NET xml control . Code behind should look something like this.

XmlDocument doc = new Document(xmlPath);
 XPathNavigator nav = doc.CreateNavigator();
xmlData.XPathNavigator = nav;
string xslFileName = Server.MapPath("~/InvoiceReport.xsl");
xmlData.TransformSource = xslFileName;
xmlData.DataBind();


Technological progress has merely provided us with more efficient means for going backwards. ~Aldous Huxley

Thursday 18 August 2011

jqGrid error at line $t.p.colModel[lvc].width += cr;

Recently I am getting an error in jqGrid plugin at the following line :-

$t.p.colModel[lvc].width += cr;


After debugging through the code this issue occurs with in the function
setGridWidth: function (nwidth, shrink)
.....
$t.p.colModel[lvc].width += cr;
.....

where nwidth is null

So while calling method setGridWidth on a grid make sure the width is a definite value and is greater than 0

Control is the wrong word. The practice is very much about sharing, and, in any creative practice, some individuals, whether partners or directors, are much closer to certain projects than I could ever be.
Norman Foster

Friday 12 August 2011

Using SQL Server Compact with FluentNHibernate

FluentNHibernate is an alternative to NHibernate that supports Object Relational Mapping framework. Actually FluentNHibernate is build on top of NHibernate that provides strongly typed mapping using c# as opposed to xml mapping (.hbm.xml).

SQL Server CE (Compact edition) is commonly used for small applications as this would not need any packaging and is a simple file copy.

Using FluentNHibernate with SQL Server CE 3.5 file has a flaw in which any changes to mapping would not be reflected in the database unless the database is re-created.

Now this has been solved in the latest version of SQL Server CE 4.0, where in any changes are automatically reflected in the database.

Here is code to configure SQL Server CE
MsSqlCeConfiguration sqlconfig = MsSqlCeConfiguration.Standard.ConnectionString(ConnectionString);
FluentConfiguration fc = Fluently.Configure();
fc = fc.Database(sqlconfig );
ISessionFactory sessionFactory = fc.Cache(c => c
   .UseQueryCache()
   .ProviderClass())
   .Mappings(m => m
   .FluentMappings.AddFromAssemblyOf())
   .ExposeConfiguration((NHibernate.Cfg.Configuration config) => new SchemaUpdate(config)
   .Execute(false, true))
   .BuildSessionFactory();




Telegraphs are machines for conveying information over extensive lines with great rapidity.
Charles Babbage


JQGrid extension to track row selection between pages

Have been using JQGrid for quite some time now and was pretty impressed with the jqGrid plugin itself.

Ok now, how about extending jqGrid for tracking selection between pages. Here is a jquery extension that does the job.

; (function($) {
    $.jgrid.extend({
        enableTracking : true,
        gridTrackingIds : null,  
        TrackPageSelection: function (Rowids, selected, currentpageno) {
            var currentPage = this.GetCurrentPage(currentpageno);
            currentPage.RowIDs = new Array();
            if(selected)
            {
                currentPage.RowIDs = Rowids;
            }
            this.UpdateSelection(currentPage);
        }, 
        GetCurrentPage: function(currentpageno){
            var selectedPages = $(this).jqGrid.gridTrackingIds;

            var currentGrid = this;
            if (selectedPages == null) {
                selectedPages = new Array();
            }

            //find current page
            var currentPage = null;
            $.each(selectedPages, function (i, item) {
                if(item.Page == currentpageno){
                    currentPage = item;
                }
            });

            if(currentPage == null)
            {
                currentPage = {
                    Page : currentpageno,
                    RowIDs : new Array()
                };
                selectedPages.push(currentPage);
            }

            $(this).jqGrid.gridTrackingIds = selectedPages;
            return currentPage;
        },
        UpdateSelection: function(currentPage){
            var selectedPages = $(this).jqGrid.gridTrackingIds;

            var currentGrid = this;
            if (selectedPages == null) {
                selectedPages = new Array();
            }

            var filteredPages = $.grep(selectedPages, function(elem, index) { 
		            return elem.Page != currentPage.Page;
	            });

            selectedPages = filteredPages;
            selectedPages.push(currentPage);

            $(this).jqGrid.gridTrackingIds = selectedPages;

        },
        TrackSelection: function (id, selected, currentpageno) {
            var selectedItems = $(this).jqGrid.gridTrackingIds;            
            //find current page
           var currentPage = this.GetCurrentPage(currentpageno);

           if(selected){                
                var itemIndex = $.inArray(id, currentPage.RowIDs);
                if(itemIndex == -1){
		            currentPage.RowIDs.push(id);
	            }
            }
            else{
                var filteredItems = $.grep(currentPage.RowIDs, function(elem, index) { 
		            return elem !== id;
	            });
	            currentPage.RowIDs = filteredItems;
	        }
            this.UpdateSelection(currentPage);                            
        },
        UpdatePageSelection: function(currentpageno){            
            var selectedItems = $(this).jqGrid.gridTrackingIds;
            if(selectedPages != null)
            {
                //find current page
                var currentPage = this.GetCurrentPage(currentpageno);                
                if(currentPage != null)
                {
                    var selectedItems = currentPage.RowIDs;
                    var currentGrid = this;
                    if(selectedItems != null) {
                        $.each(currentGrid.jqGrid("getDataIDs"), function (i, id) {
                            if($.inArray(id, selectedItems) > -1) {
                                currentGrid.setSelection(id, false);
                            }
                        });                        
                    }
                }
            }
        }
        ResetTracking: function(){
            $(this).jqGrid.gridTrackingIds = null;            
        }
    });
})(jQuery);



All you need is to just copy this into a .js file and add it to your project. Now on row select just call this

onSelectRow: function(rowid,selected)
{
  var pageno = $(this).getGridParam('page');
  $(this).TrackSelection(rowid,selected,pageno);   
}




At each increase of knowledge, as well as on the contrivance of every new tool, human labour becomes abridged.
Charles Babbage

Tuesday 9 August 2011

JQGrid sorting with date and time column using localization

Have been using JQGrid for quite some time now and have got stuck with unable to sort on DateTime columns. But finally managed a way to be able to handle this. Not only to allow sorting but also should be able use localization and display/sort in current local format.

Not use if this is the right way and works for me. The various DateTime formats available are listed at DateTime formats. Assuming the default date format is "The General Date Short Time ("g") Format Specifier".

DateTimeFormatInfo dateformatInfo = Thread.CurrentThread.CurrentCulture.DateTimeFormat;
string dateFormat = dateformatInfo.ShortDatePattern;

Now that we know the dateformat we are going to use is defined in a variable "dateFormat". Convert this date format string to JQGrid format.
public string ConverToJQGridDateFormat(string DateFormat)
{ 
            // Day
            DateFormat = DateFormat.Replace("dddd", "d");
            DateFormat = DateFormat.Replace("ddd", "d");
            DateFormat = DateFormat.Replace("dd", "d");
            // Month            
            DateFormat = DateFormat.Replace("MMMM", "M");
            DateFormat = DateFormat.Replace("MMM", "M");
            DateFormat = DateFormat.Replace("MM", "m");
            DateFormat = DateFormat.Replace("M", "m");
            // Year
            DateFormat = DateFormat.Replace("yyyy", "Y");
            DateFormat = DateFormat.Replace("yyy", "y");
            DateFormat = DateFormat.Replace("yy", "y");
            return DateFormat;
}


Ok now we have got our JQGrid date format, just apply this to colmodel options. Finally the column for "Invoice date" should be rendered as

name: 'InvDate',index: 'InvDate',sorttype:'date',formatter:'date',formatoptions:{srcformat:'d/m/Y',newformat:'d/m/Y'}
Another mode of accumulating power arises from lifting a weight and then allowing it to fall.
- Charles Babbage


Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers