Wednesday, May 22, 2013

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);
        }

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);
        }

Kendo - KnockOut Grid Bind

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Content/kendo.common.min.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Content/kendo.blueopal.min.css")" rel="stylesheet" type="text/css" />


<script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>

<script src="../../Scripts/knockout-2.2.0.debug.js" type="text/javascript"></script>

<script src="../../Scripts/kendo.all.min.js" type="text/javascript"></script>

<script src="../../Scripts/knockout-kendo.min.js" type="text/javascript"></script>


HTML

                                              


<div data-bind='kendoGrid:gridConfig'></div>  

                                               

JavaScript


<script language="javascript" type="text/javascript">

$(document).ready(function () {
      
        $.ajaxSetup({ async: false });
        //var Data= [{ "ShipCity": "Kolkata", "ShipName": "Pinaki GROUP" }, { "ShipCity": "Mumbai", "ShipName": "Pinaki SOL"}];
        var Data = null;
        function DataFunction() {
            $.post("/BkCode/BookResult", null, function (d) {
                Data = d;
            });
            return Data;
        }
      
        var ViewModel = function () {
            this.gridConfig = {
                data: null,
                dataSource: {
                    type: "odata",
                    data: DataFunction(), //This is use to access data from database using jQuery
                                          //   and return data in Json format
                    //data: Data,
                    schema: {
                        model: {
                            fields: {
                                ShipCity: {
                                    type: "string"
                                   
                                },
                                ShipName: {
                                    type: "string"
                                }
                            }
                        }
                    },
                    pageSize: 10 //,
                    //serverPaging: true,
                    //serverFiltering: true,
                    //serverSorting: true
                },
                columns: [{
                    field: "ShipCity",
                    title: "Id",
                    filterable: false
                },
                {
                    field: "ShipName",
                    title: "Company Name",
                    filterable: true
                },
                {
                    command: ["edit", "destroy"],
                    filterable: false
                }] ,
                height: 550,
                scrollable: false,
                pageable: true,
                sortable: true,
                groupable: true,
                filterable: true,
                editable: "inline", //popup
                save: function () {
                    this.refresh();
                }
            };
        };
        ko.applyBindings(new ViewModel());
    })

</script>

C#

public JsonResult BookResult()
        {
            var result = from s in bk.GetPrmCompanies()
                         select new book{
                             ShipCity = s.Id,
                             ShipName = s.CoNames
                         };
            DB.Configuration.ProxyCreationEnabled = false;
            return Json(result, JsonRequestBehavior.AllowGet); //Content(sd, "text/xml");
        }

Wednesday, December 12, 2012

How To Buy A Blogspot Domain

1.          First  you login to blogspot.com
2.          Then if you have account go to the dashboard

3.          Click on the Setting. And select About Our New Look and click
4.          Choose About URLs from left panel and click
5.       Click custom domain. In newly open page.
6.       Choose radio button Buy a custom domain through Blogger.

7.       Click  Google Checkout New window icon link in this page.

8.       Google Wallet logging page will open. Login with your user name and password.


9.       Now You will get the shopping page. Fill data with correct data including Payment method.

Transaction Commit And Rollback in LINQ

How to Use transaction.
When we want to save data to multiple table or in multiple time in a table use transaction.
follow code snip below. 
Class Abc {
//Object Declaration
ProjectRepository pr = new ProjectRepository();
DBDataContext DBObject = new DBDataContext();
//Action
public ActionResult FormEntry(FormCollection fc)
{
  System.Data.Common.DbTransaction Tran=null;
  DBObject.Connection.Open();
  Tran = DBObject.Connection.BeginTransaction();
  DBObject.Transaction = Tran;
           
 try
 {
       //---Code of insert or Update---
               DataTable dtc = (DataTable)SessionBag.Current.ChequeDetailsXV;
               if (dtc.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtc.Rows)
                        {
                            CapitalDetail Pc = new CapitalDetail();
                            Pc.PrGroup_ID = Convert.ToInt32(dr["PrGroup_ID"]);
                            Pc.Capi_Amount = Convert.ToInt32(dr["Amount"]);
                            Pc.Capi_Bank = Convert.ToString(dr["ChqBankBranch"]);
                            Pc.Capi_Bank_Branch = Convert.ToString(dr["ChqBankBranch"]);
                            //Pc.Capi_OutStation = Convert.ToString(dr["DrawNo"]);
                            Pc.Capi_ChequeNo = Convert.ToInt32(dr["ChqNo"]);
                            Pc.Capi_Date = Convert.ToDateTime(dr["ChqDate"]);
                            Pc.Capi_EntryDate = Convert.ToDateTime(DateTime.Now);
                            Pc.Capi_Type = Convert.ToString("Cheque");
                           
                            pr.Add(Pc);
                        }
                    }
        pr.Save();
        Tran.Commit();
 }
catch (Exception ex)
 {
        Tran.Rollback();
 }
finally
{
if (DBObject.Connection != null && DBObject.Connection.State ==                                                                                                                      System.Data.ConnectionState.Open)
       {
           DBObject.Connection.Close();
                       
       }
     
}
}