Friday, December 7, 2012

Group by and Sub group in Linq



Created a result set (Using IBATIS.NET Datamapper technology to load object using Stored Procedure method) as on object.

IList<CLASS1> objReport1 = new List<CLASS1>();

IList<CLASS> objReportBase = DataLayer.MethodName(strParam, 1, "N");

if (objReportBase.Count > 0)
{
               objReportNew = (from p in objReportBase
                                group p by new
                                {
                                    p.USERID,
                                    p.DISPLAYUSERID,
                                    p.LASTNAME,
                                    p.FIRSTNAME
                                } into g
                                orderby g.Key.LASTNAME, g.Key.SUITENAME
                                select new CLASS1
                                {
                                    USERID = g.Key.USERID,
                                    DISPLAYUSERID = g.Key.DISPLAYUSERID,
                                    LASTNAME = g.Key.LASTNAME,
                                    FIRSTNAME = g.Key.FIRSTNAME,
                                   
                                    subPVCs = g.Select(l => new
                                                {
                                                    l.COURSENAME,
                                                    l.MASTEREDDATE,
                                                    l.ASSIGNEDDATE,
                                                    l.MASTEREDSCORE,
                                                }
                                             ).Distinct()
                                }).ToList<CLASS1>();

                objReportBase = null;
}
           
public class BASECLASS
{
        public virtual int USERID { get; set; }
        public virtual string DISPLAYUSERID { get; set; }
        public virtual string LASTNAME { get; set; }
        public virtual string FIRSTNAME { get; set; }
        public virtual string COURSENAME { gets; set; }
        public virtual string MASTEREDDATE { get; set; }
        public virtual string ASSIGNEDDATE { get; set; }
        public virtual string MASTEREDSCORE { get; set; }
}
public class CLASS1
{
        public virtual int USERID { get; set; }
        public virtual string DISPLAYUSERID { get; set; }
        public virtual string LASTNAME { get; set; }
        public virtual string FIRSTNAME { get; set; }

        public virtual IEnumerable subPVCs { get; set; }

}

public class subPVC
{
        public virtual int USERID { get; set; }
        public virtual string COURSENAME { gets; set; }
        public virtual string MASTEREDDATE { get; set; }
        public virtual string ASSIGNEDDATE { get; set; }
        public virtual string MASTEREDSCORE { get; set; }
}

Thursday, November 15, 2012

TOP 10 USEFULL MOBILE APPLICATION

1) UNIVERSAL REMOTES - As smartphones don't have IR emitters, one has to install a dongle. MP3 mobile accessory (Rs 350) to be connected to the phone's 3.5 mm jack. Dijit Universal Remote for iOS needs to be paired with Griffin Technology's Beacon.

2) BUSINESS CARDS - scan business cards and copy the information on the card to the phone as well as on the cloud.
            i) CamCard
            ii) ScanBizCards
            iii) WorldCard Mobile

3) YOUR CAR KEY - This remote key comes in the form of the Viper SmartStart app for iOS, Android and BlackBerry smartphones. But it requires you to have the Viper Smart Start GPS device that costs around $400 (about Rs 21,200). You need to download the free app and pair it with the GPS device.

4) MEASURING TAPES - These commonly use trigonometry to calculate distances while some use GPS, better for irregular surfaces or areas.

5) HEALTH AND FITNESS GUIDES - You can find free yoga, cardio, weight training and other fitness guides in the application markets for Android and iOS.

6) PHYSICAL SWITCHES - This could be a little in the future.
            The Crestron Mobile control app for iPhone, iPad and Android devices does involve a sizable investment but it's worth it if you have the cash to spare.

7) YOUR WALLET - With Near-Field Communication (NFC) hardware coming to smartphones, everyone is expecting a gradual decline in the use of plastic cards and cash.

8) BARCODE AND QR READERS - Barcodes and QR codes are ubiquitous.

9) WI-FI ROUTERS - If you own the latest Android or Windows smartphone, you can use the phone's data connection to create a secure Wi-Fi network of your own. This option is available in your settings menu as 'Wi-Fi hotspot, Internet tethering or Internet sharing'. You can secure this network with a password and connect up to five devices to surf the Net.

10) CABLE TELEVISION - There are apps that enable you to stream live television onto a handset. Zenga TV, ditto TV, mimobiTV, MunduTV are some popular live streaming apps.

Monday, October 29, 2012

The iBATIS frameworks

iBATIS consists of two separate frameworks

1.    Data Mapper framework: specifically for OR mapping, Executes your SQL and maps the results back to .Net domain objects
2.    DAO (Data Access objects) framework: gives your application a clean and consistent way to access underlying data.

Thursday, October 25, 2012

Post data via Jquery ajax and response as Json in asp.net

Populate select list dynamically using jquery ajax postback and return the string from process page as json.

Html page:

// Jquery script to be include in the page
<script type="text/javascript" src="folderpath/jquery-1.8.0.js"></script>

//Html controls on the page
<input type="button" id="btnGo" value="Click to Show Records - JSON"  />

<select id="lstUserList" name="lstUserList" size="12" multiple="multiple">
<option value="" text="none"></option>
</select>


Javascript function:

<script type="text/javascript">

    $(document).ready(function() {
        $('#btnGo').click(function(){
//clearing select options
            $('#lstUserList').empty();

            var hdndata = "test";// data to post for the process page
    
            var post = "hdndata=" + hdndata;
    
            $.ajax({
                type: "POST",
                url: "folderpath/pagename.aspx",
                data: post,
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                dataType: "json",
                success: function(msg) {
                    $(outputlist(msg.Table));
                }
            });
        });
    });

    function outputlist(dataTable)
    {
        var listItems = [];
        for (var row in dataTable)
        {
            var strData = '';
            strData = dataTable[row]["LASTNAME"] + ' ' + dataTable[row]["FIRSTNAME"] + ' (' + dataTable[row]["DISPLAYUSERID"] + ')';
            listItems.push('<option class="ACTIVE' + dataTable[row]["CSSCLASS"] + '" value="' + dataTable[row]["USERID"] + '" title="' + strData + '">' + strData + '</option>');
        }
        $('#lstUserList').append(listItems.join(''));
    }
</script> 


Process page:

'Process input parameter and get the result as dataset and pass it to the method ToJson on JsonMethods class
dim ds as new dataset
ds = obj.methodname(parameter)
Response.Write(JsonMethods.ToJson(ds))


Class file:

Imports System.Data
Imports System.Collections.Generic
Imports System.Runtime.Serialization.Json
Imports System.IO
Imports System.Text
Imports System.Web.Script.Serialization

Public Class JsonMethods
    Private Shared Function RowsToDictionary(ByVal table As DataTable) As List(Of Dictionary(Of String, Object))
        Dim objs As New List(Of Dictionary(Of String, Object))()
        For Each dr As DataRow In table.Rows
            Dim drow As New Dictionary(Of String, Object)()
            For i As Integer = 0 To table.Columns.Count - 1
                drow.Add(table.Columns(i).ColumnName, dr(i))
            Next
            objs.Add(drow)
        Next
        Return objs
    End Function

    Public Shared Function ToJson(ByVal table As DataTable) As Dictionary(Of String, Object)
        Dim d As New Dictionary(Of String, Object)()
        d.Add(table.TableName, RowsToDictionary(table))
        Return d
    End Function

    Public Shared Function ToJson(ByVal data As DataSet) As String 
        Dim d As New Dictionary(Of String, Object)()
        For Each table As DataTable In data.Tables
            d.Add(table.TableName, RowsToDictionary(table))
        Next
        Dim json As New JavaScriptSerializer
        json.MaxJsonLength = Int32.MaxValue
        Return json.Serialize(d)
    End Function

End Class