Thursday, November 22, 2012

Pan Number format and Duplication entry validation in KendoUi



 Checking from database using json and Controler's action where controler is Validation and Action is CheckPanNo . Then we check format using test function. and error message set to messages section of  kendoValidator function.


Java Script

 

///Pan No Duplication checking
        var validatable = $("#Pan").kendoValidator({
            onfocusout: true,
            onkeyup: true,
            rules: {
                PanNo: function (input) {
                    $.post("/Validation/CheckPanNo", { PanNo: $("#Pan").val() }, function (data) { b1 = data; })
                    return b1;
                },
                PanFormat: function (input) {
                    // return validatePanCard('Pan');
                    var value = input.val();
                    var regex1 = /^[A-Z]{5}\d{4}[A-Z]{1}$/;
                    if (!regex1.test(value) || value.length != 10) {

                        return false;
                    }
                    return true;
                }
               

            },

            messages: {
                PanNo: "Already Exist",
                PanFormat: "Not a currect format"
            }
        }).data("kendoValidator");


 Action

 

[HttpPost]
        public JsonResult CheckPanNo(string PanNo)
        {
            bool IsOk = projectRepository.CheckPanNumber(PanNo);
            return Json(IsOk, JsonRequestBehavior.AllowGet);
        }

 



Wednesday, November 21, 2012

How to Binding Dropdown Using Knockout JS


Using jquery, we access date from Action called Ko_ShowBranch in a controller caller ListObject. This action access data from database using a function called ShowAll_Branch() and to return Json result in text and value property we write below line this way.
ShowAll_Branch().Select(p => new { text =p.BranchName , value = p.ID.ToString() });

In Html Value property and Text property are set using optionsValue: and optionsText:


Javascript


 viewModel = {
        Branch: ko.observableArray()

    };

    $(function () {
        $.getJSON('http://localhost:3400/ListObject/Ko_ShowBranch', null
          function (response)  {
            viewModel.Branch(response);
        });
         ko.applyBindings(viewModel);

    });


Html

 <select data-bind="options: Branch, optionsCaption: 'Choose Branch...',
            optionsValue: function(item) { return item.value; },
            optionsText: function(item) { return item.text; }" id="Branch" name="Branch">   </select>


Controler


 public JsonResult Ko_ShowBranch()
        {
            var result = projectRepository.ShowAll_Branch().Select(p => new { text =                      p.BranchName, value = p.ID.ToString() });
            return Json(result, JsonRequestBehavior.AllowGet);
        }


Monday, November 19, 2012

How can I format a json date in dd/mm/yy format in javascript


Json return date as timestamp to convert that date to our normal date format we first convert timestamp to Date . then we get day, month, year from Date and format it as dd/mm/yyyy or mm/dd/yyyy or yyyy/mm/dd and other format.


function EditCheque(id) {
        $.post("/Partner/ChqEdit", { id: id }, function (data) {


var date = new Date(parseInt(data.ChqDate.substr(6)));
$("#ChqDate").val( date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear());
});

SQL Optimization

  SQL Optimization  1. Add where on your query  2. If you remove some data after the data return then remove the remove condition in the sel...