Tuesday 29 March 2016

Kendo Chart

Controller Code :

 public JsonResult FillScoreCard()
        {
            List<ChartMetadata> lst = new List<ChartMetadata>() { 
            new ChartMetadata(){ Value=100,Text="Siv",Code="#00FFFF"},
            new ChartMetadata(){ Value=200,Text="Sankar",Code="#FFFF00"},
            new ChartMetadata(){ Value=300,Text="Mahadev",Code="#4E9258"},
            };
            return Json(lst,JsonRequestBehavior.AllowGet);

        }


View code :

<div style="width:100%;">
    <div style="width:49%;float:left; border:1px solid #808080; margin-top:50px">

        <div id="ScoreCard" style="width:500px;"></div>

    </div>
    <div style="width:49%;float:right;border:1px solid #808080;margin-top:50px">

        <div id="PurchaseSummary" style="width:500px;"></div>

    </div>

</div>
<script>
    $(function () {
        $.ajax({
            url: '@Url.Action("FillScoreCard", "VendorPortal")',
            type: 'GET',
            dataType: 'json',
            cache: false,
            success: function (data1) {
                $("#ScoreCard").kendoChart({
                    dataSource: {
                        data: data1
                    },
                    title: {
                        text: "Score Card",
                        color: "#2B65EC"
                    },
                    legend: {
                        position: "left"
                    },
                    seriesDefaults: {
                        type: "column",
                        labels: {
                            visible: true,
                            background: "transparent"
                        }
                    },
                    categoryAxis: [{
                        field: "Text",
                        majorGridLines: {
                            visible: false
                        },
                     
                        title: {
                            text: "Criteria",
                            background: "#4682B4",
                            color: "#ffffff",
                            padding: 15

                        },
                        labels: {

                        }

                    }],
                    valueAxis: [{
                        title: {
                            text: "Count",
                            background: "#4682B4",
                            color: "#ffffff",
                            padding: 15,
                        },
                        majorUnit: 50,
                        max: 500,
                        min: 0 ,
                        majorGridLines: {
                            visible: false
                        },
                    }],
                    series: [{
                        field: "Value",
                        colorField: "Code"
                    }

                    ]
                });
            }

        });
        $.ajax({
            url: '@Url.Action("FillPurchaseSummary", "VendorPortal")',
            type: 'GET',
            dataType: 'json',
            cache: false,
            success: function (data1) {
                $("#PurchaseSummary").kendoChart({
                    dataSource: {
                        data: data1
                    },
                    title: {
                        text: "Purchase Summary",
                        color: "#2B65EC"
                    },
                    legend: {
                        position: "left"
                    },
                    seriesDefaults: {
                        type: "column",
                        labels: {
                            visible: true,
                            background: "transparent"
                        }
                    },
                    categoryAxis: [{
                        field: "Text",
                        majorGridLines: {
                            visible: false
                        },
                        title: {
                            text: "Status",
                            background: "#4682B4",
                            color: "#ffffff",
                            padding: 15
                        }

                    }],
                    valueAxis: [{
                        title: {
                            text: "Count",
                            background: "#4682B4",
                            color: "#ffffff",
                            padding: 15
                        },
                        majorUnit: 50,
                        max: 500,
                        min: 0,
                        majorGridLines: {
                            visible: false
                        },
                    }],
                    series: [{

                        field: "Value",
                        colorField: "Code"
                    }

                    ]
                });
            }

        });

    });

</script>


Y-axis value fill dynamically


<script>


$(function () {

       




$.ajax({


url: '@Url.Action("FillScoreCard", "VendorPortal")',

type: 'GET',

dataType: 'json',

cache: false,






data:{VendorId:@Model.VendorId},


success: function (data1) {

var max1=0;

var interval=0;

for(var i=0;i<data1.length;i++)

if(max1<data1[i].Value)






max1=data1[i].Value;


max1=max1*2;


if(max1<=100)






interval=5;


else if(max1>100 && max1<=200)






interval=10;


else if(max1>200 && max1<=300)






interval=20;


else





interval=50;


$("#ScoreCard").kendoChart({






dataSource: {


data: data1


},





legend: {


position: "left"





},


seriesDefaults: {


type: "column",






labels: {


visible: true,

background: "transparent"





}


},


categoryAxis: [{


field: "Text",






majorGridLines: {


visible: false





},


title: {


text: "(Product Count) Criteria",

background: "#4682B4",

color: "#ffffff",






padding: 10


},


labels: {


}


}],


valueAxis: [{


title: {


text: "Count",

background: "#4682B4",

color: "#ffffff",






padding: 10,


},


majorUnit: interval,


max: max1,


min: 0,


majorGridLines: {


visible: false





},


}],


series: [{


field: "Value",

colorField: "Code"





}


]


});


}


});


$.ajax({


url: '@Url.Action("FillPurchaseSummary", "VendorPortal")',

type: 'GET',

dataType: 'json',

cache: false,






data:{VendorId:@Model.VendorId},


success: function (data1) {

var max1=0;

var interval=0;

for(var i=0;i<data1.length;i++)

if(max1<data1[i].Value)






max1=data1[i].Value;


max1=max1*2;


if(max1<=100)






interval=5;


else if(max1>100 && max1<=200)






interval=10;


else if(max1>200 && max1<=300)






interval=20;


else





interval=50;


$("#PurchaseSummary").kendoChart({






dataSource: {


data: data1


},





legend: {


position: "left"





},


seriesDefaults: {


type: "column",






labels: {


visible: true,

background: "transparent"





}


},


categoryAxis: [{


field: "Text",






majorGridLines: {


visible: false





},


title: {


text: "Status",

background: "#4682B4",

color: "#ffffff",






padding: 10


}


}],


valueAxis: [{


title: {


text: "Count",

background: "#4682B4",

color: "#ffffff",






padding: 10


},


majorUnit: interval,


max: max1,


min: 0,


majorGridLines: {


visible: false





},


}],


series: [{


field: "Value",

colorField: "Code"





}


]


});


}


});


});


</script>





Sunday 27 March 2016

Add, Edit & Delete in kendo gride.

 var date = new Date();
        var currentYear = date.getFullYear();
        var mindate = "01/01/" + currentYear;
        var maxdate = "12/31/" + currentYear;
       


     
        $("#holidays-grid").kendoGrid({
            dataSource: {
                type: "json",
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("FillGride", "VendorPortal", new { VendorId = Model.VendorId, Year = Model.SelectedYear }))",
                        type: "POST",
                        dataType: "json",


                    },
                    create: {
                        url: "@Html.Raw(Url.Action("SaveData", "VendorPortal", new { VendorId = Model.VendorId }))",
                        type: "POST",
                        dataType: "json"
                    },
                    update: {
                        url: "@Html.Raw(Url.Action("UpdateData", "VendorPortal", new { VendorId = Model.VendorId }))",
                        type: "POST",
                        dataType: "json"
                    },
                    destroy: {
                        url: "@Html.Raw(Url.Action("DeleteData", "VendorPortal"))",
                        type: "POST",
                        dataType: "json"
                    },
                    parameterMap: function (data, operation) {
                        if (operation != "read") {
                            return data;
                        } else {
                            return JSON.stringify(data);
                        }
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors",
                    model: {
                        id: "Id",
                        fields: {
                            Date: { editable: true, type: "date", format: "{0:MM/dd/yyyy}", validation: { required: true, min: new Date(mindate), max: new Date(maxdate) } },
                            Month: { editable: false, type: "string" },
                            // HolidayName:{editable: true, type: "string"},
                            HolidayName: {
                                editable: true, type: "string", validation: {
                                    required: true,
                                    maxlength:
                                            function (input) {
                                                if (input.val().length > 80) {
                                                    input.attr("data-maxlength-msg", "Max length is 80");
                                                    return false;
                                                }
                                                return true;
                                            }
                                }
                            },
                            Id: { editable: false, type: "number" }
                        }
                    }

                },
                requestEnd: function (e) {
                    if (e.type == "create" || e.type == "update") {
                        this.read();
                    }
                },
                error: function (e) {
                    var grid = $('#holidays-grid').data('kendoGrid');
                    grid.dataSource.read();
                },

                serverPaging: false,
                serverFiltering: false,
                serverSorting: false
            },
            filterable: {
                extra: false,
                operators: {
                    string: { contains: "Contains" }
                }
            },
            toolbar: [{ name: "create", text: "Add Holiday" }],
            sortable: {
                mode: "single",
                allowUnsort: false
            },
            editable: {
                confirmation: true,
                mode: "inline"
            },
            scrollable: false,
            columns: [
                { field: "Date", title: "Date", format: "{0:MM/dd/yyyy}", width: 145 },
                { field: "Month", title: "Month", attributes: { style: "text-align:center" }, },
                { field: "HolidayName", title: "Holiday Name" },

                {
                    title: "Action",
                    attributes: { style: "text-align:center" },
                    command: [{
                        name: "edit",
                        text: ""
                    }, {
                        name: "Delete", text: "", imageClass: "k-icon k-delete", click: function (e) {
                            e.preventDefault();
                            var dataItem = this.dataItem($(e.target).closest("tr"));
                            //*******
                            var kendoWindow = $("<div />").kendoWindow({
                                title: "Confirm",
                                resizable: false,
                                modal: true,
                                width: 500,
                                height: 200
                            });
                            kendoWindow.data("kendoWindow")
                            .content($("#delete-confirmation").html())
                            .center().open();

                            kendoWindow
                                .find(".delete-confirm,.delete-cancel")
                                    .click(function () {
                                        if ($(this).hasClass("delete-confirm")) {

                                            $.ajax({
                                                cache: false,
                                                type: "POST",
                                                url: "@(Url.Action("DeleteData", "VendorPortal"))",
                                                data: { Id: dataItem.Id },
                                                success: function () {
                                                    var grid = $('#holidays-grid').data('kendoGrid');
                                                    grid.dataSource.read();
                                                }
                                            });

                                        }
                                        kendoWindow.data("kendoWindow").close();

                                    })
                           .end();

                        }
                    }],

                }
            ],
            dataBound: function () {
                if ($('#holidays-grid').find("tr").length == 1) {
                    $('#holidays-grid').find('tbody')
                            .append('<tr class="kendo-data-row"><td colspan="4" style="text-align:center"><b>No Results Found!</b></td></tr>');
                }

                var selectedYear = $("#ddl").val();
                var year = new Date().getFullYear();

                if (selectedYear != year) {

                    $(".k-grid-toolbar", "#holidays-grid").hide();
                    $(".k-grid-edit", "#holidays-grid").hide();
                    $(".k-grid-delete", "#holidays-grid").hide();
                }
                else {
                    $(".k-grid-toolbar", "#holidays-grid").show();
                }

            }

        });


Controller Code

 public JsonResult FillGride(DataSourceRequest command, int VendorId, int Year)
        {
            var gridModel = new DataSourceResult();
            var data = _VendorHolidayCalendarService.GetAllVendorHolidayCalendar(command.Page - 1, command.PageSize);
            if (data.Count != 0)
            {
                gridModel.Data = data.Where(n => n.Date.Value.Year == Year).Select(m =>
               new CalendarVM
               {
                   Id = m.Id,
                   Date = m.Date.Value.ToShortDateString(),
                   Month = m.Date.Value.ToString("MMMM"),
                   HolidayName = m.HolidayName,
               }
               ).ToList();
            }
            else
            {
                List<CalendarVM> lst = new List<CalendarVM>();
                gridModel.Data = lst;
            }


            return Json(gridModel, JsonRequestBehavior.AllowGet);
        }
        public void SaveData(CalendarVM vc,int VendorId)
        {
            DateTime dt = Convert.ToDateTime(vc.Date.ToString().Substring(4, 11));
            VendorHolidayCalendar vendorHolidayCalendar = new VendorHolidayCalendar();
            vendorHolidayCalendar.Date = dt;
            vendorHolidayCalendar.HolidayName = vc.HolidayName;
            vendorHolidayCalendar.VendorId = VendorId;
            vendorHolidayCalendar.CreatedBy = VendorId;
            vendorHolidayCalendar.CreatedDate = DateTime.Today;
            _VendorHolidayCalendarService.InsertVendorHolidayCalendar(vendorHolidayCalendar);
         

        }
       
        public void UpdateData(CalendarVM vc,int VendorId)
        {
            DateTime dt = Convert.ToDateTime(vc.Date.ToString().Substring(4, 11));
            VendorHolidayCalendar vendorHolidayCalendar = new VendorHolidayCalendar();
            vendorHolidayCalendar.Id = vc.Id;
            vendorHolidayCalendar.Date = dt;
            vendorHolidayCalendar.HolidayName = vc.HolidayName;
            vendorHolidayCalendar.VendorId = VendorId;
            vendorHolidayCalendar.UpdatedBy = VendorId;
            vendorHolidayCalendar.UpdatedDate = DateTime.Today;
            _VendorHolidayCalendarService.UpdateVendorHolidayCalendar(vendorHolidayCalendar);
         
        }
        public JsonResult DeleteData(int Id)
        {
            _VendorHolidayCalendarService.DeleteVendorHolidayCalendar(Id);
            return Json("Data deleteted", JsonRequestBehavior.AllowGet);
        }

Tuesday 22 March 2016

question & answer

What is a static class?
-A class that cannot be instantiated
-It is best for use with common code libraries

What is a singleton?
-A class that provides a single instance of itself

What is the difference between a static class and a singleton?
-A static class cannot be instantiated
-A singleton can instantiate itself and provide that instance



Object
Represents one specific thing Example: Hammer or Saw
Defines one thing created from that template
Created at runtime with the new keyword

Class
Represents things of the same type
Example: Product
Defines the template specifying the data and processing associated with all things of that type
Created at development time with code


What is the difference between a constant and a read-only field?
-A constant
•Is static
•Assigned on the declaration
•Assigned to an expression that is fully evaluated at compile time
-A read-only field
•Can be static or non-static
•Assigned in the declaration or in a constructor
•Assigned to any valid expression
What is the primary purpose of a property?
-To guard access to the fields of the class
-And optionally provide a location for logic

What are auto-implementedproperties?
-Short cut syntax for defining an implicit backing field with its associated property getter and setter


What is the primary purpose of a method?
-To implement the logic required for specific behavior or functionality in a class

What is the difference between a parameter and an argument?
-A parameteris part of the method signature
-An argumentis part of the method call

What is method overloading?
-Methods with the same name and purpose but different signatures

What is method chaining?
-One method overload calls another overload to prevent repeated code

When is it best to use method overloading vs. method overriding?
-Use overloading when one method requires multiple signatures
•Such as a GetCustomer(id) to get a customer by Id and GetCustomer(name)

to get the customer by name
-Use overridingwhen replacing a method defined higher up the object

hierarchy.
•Such as replacing the ToString() method

What is an expression-bodied method?
-A syntax shortcut for single statement methods that return a value

What does it mean to say that C# strings are immutable?
-It means that strings cannot be modified once they are created.
§Is a string a value type or a reference type?
-A string is a referencetype
-That acts like a valuetype
§What is the best way to check for nullstrings?
-
It depends
-
Using String.IsNullOrWhiteSpaceis great when checking nulls for a code block
-
Using the new C# 6 null-conditional operator is great for code statements
[18:35:30] Shantanu Patel | Extension 3363: What are the benefits to using StringBuilder?
-The .NET StringBuilderclass is mutable, meaning that it can be readily changed.
-Using StringBuilderis therefore more efficient when appending lots of strings.
[18:37:43] Shantanu Patel | Extension 3363: using System;

class Program
{
    static void Main()
    {
 int val = 0;

 Example1(val);
 Console.WriteLine(val); // Still 0!

 Example2(ref val);
 Console.WriteLine(val); // Now 2!

 Example3(out val);
 Console.WriteLine(val); // Now 3!
    }

    static void Example1(int value)
    {
 value = 1;
    }

    static void Example2(ref int value)
    {
 value = 2;
    }

    static void Example3(out int value)
    {
 value = 3;
    }
}

Output

0
2
3

how to open kendo poup in dynamically.

<div id='popup' style='display:none;'>
    <h3></h3>
    <div class="options submitStyle k-button-add"><br /><br /><br />
        <input id="closePopupMessage" type="button" value="OK" class="k-button" />
    </div>
</div>

<script>
$(function(){
 $('#tb').on('click', "a[name='del']", function () {
            var $row = $(this).parents('tr');
            if ($('#tb tr').length == 2) {
                openPopUpMessage("Message", " This record can not be deleted");
            }
});
function openPopUpMessage(title, message) {
            var window = $('#popup');
            window.find('h3').html(message);
            window.kendoWindow({
                modal: true,
                title: title,
                actions: ['Close'],
                width: 500,
                height:200
            });
            window.data('kendoWindow').center().open();
        }
        $('#closePopupMessage').click(function () {
            var window = $('#popup');
            window.data('kendoWindow').close();
        });

});
</script>

Sunday 20 March 2016

Regular Expression for number in MVC

 [RegularExpression(@"[1-9][0-9]*$", ErrorMessage = "You can enter only positive number and greater than zero.")]


 [RegularExpression(@"[0-9]*\d{9}$", ErrorMessage = "you can enter 9 digit number.")]