Wednesday, August 27, 2014

kendo grid checkbox check validation

In the following above image i want to transfer from left side grid data to right side grid & only the selected grid item. I will check that
- The left grid can check more than one checkbox
- right side grid will check only one.
- left & right side selection item will not same.

Then all the selected check box in the left side will get for right side person for save or update as you want.

Transfer button click:


 <button type="submit" class="btn btn-mini btn-primary" onclick="AccountsManagerTransferResponsiblity()">  
           <i class="icon-retweet"></i>Transfer  
         </button>  

Script:


  function AccountsManagerTransferResponsiblity() {  
     var gridData1 = $("#CustomerAccountManagerKendoGrid1").data("kendoGrid").dataSource.data();  
     var gridData2 = $("#CustomerAccountManagerKendoGrid2").data("kendoGrid").dataSource.data();  
     if (!CheckGridConstraint(gridData1, gridData2)) return;  
     // var gEmpID1 = GetSelectedEmpID(gridData1);  
     // Get selected grid value   
     var gEmpID2 = GetSelectedEmpID(gridData2);  
     //get the grid from left side   
      var gridData = $("#CustomerAccountManagerKendoGrid1").data("kendoGrid").dataSource.data();  
     // set model data   
      for (var i = 0; i < gridData.length; i++) {  
      }  
     var postUrl;  
     var paramValue;  
     // Your controller action path  
     postUrl = '@Url.Content("~/Billing/CustomerAccountManage/AccountsManagerTransferResponsiblityAction")';  
     paramValue = JSON.stringify(  
     {  
       'pEmpID1': gEmpID1  
       , 'pEmpID2': gEmpID2  
       , ManagerList: gridData // passing the grid value in controller as parameter  
     });  
     $.ajax({  
       url: postUrl,  
       type: 'POST',  
       dataType: 'json',  
       data: paramValue,  
       contentType: 'application/json; charset=utf-8',  
       success: function (result) {  
         console.log(result);  
       },  
       error: function (objAjaxRequest, strError) {  
         var respText = objAjaxRequest.responseText;  
         console.log(respText);  
       }  
     });  
   }  


Validation Script:


  function CheckGridConstraint(gridData1, gridData2) {  
     if (!CheckMultipleSelection(gridData1, gridData2)) {  
       return false;  
     }  
     if (!CheckSameEmployeeSelect(gridData1, gridData2)) {  
       alert("Please select different employee to TransferResponsiblity");  
       return false;  
     }  
     return true;  
   }  
   function CheckMultipleSelection(gridData1, gridData2) {  
     var gridCheckCount = 0;  
     //for (var i = 0; i < gridData1.length; i++) {  
     //  if (gridData1[i].SelectStatus == true) {  
     //    gridCheckCount += 1;  
     //  }  
     //}  
     if (gridCheckCount > 1) {  
       alert("Please select one record for left grid");  
       return false;  
     }  
     gridCheckCount = 0;  
     for (var i = 0; i < gridData2.length; i++) {  
       if (gridData2[i].SelectStatus == true) {  
         gridCheckCount += 1;  
       }  
     }  
     if (gridCheckCount > 1) {  
       alert("Please select one record for right grid");  
       return false;  
     }  
     return true;  
   }  
   function CheckSameEmployeeSelect(gridData1, gridData2) {  
     var gd1EmpID;  
     var gd2EmpID;  
     for (var i = 0; i < gridData1.length; i++) {  
       if (gridData1[i].SelectStatus == true) {  
         gd1EmpID = gridData1[i].GEmployeeGenInfoID;  
         for (var j = 0; j < gridData2.length; j++) {  
           if (gridData2[i].SelectStatus == true) {  
             gd2EmpID = gridData2[j].GEmployeeGenInfoID;  
             if (gd1EmpID == gd2EmpID) {  
               return false;  
             }  
           }  
         }  
       }  
     }  
     return true;  
   }  

Get right side single check value:


  function GetSelectedEmpID(gridData) {  
     for (var i = 0; i < gridData.length; i++) {  
       if (gridData[i].SelectStatus == true) {  
         return gridData[i].GEmployeeGenInfoID;  
       }  
     }  
   }  

Get value in controller:


   public ActionResult AccountsManagerTransferResponsiblityAction(string pEmpID1, string pEmpID2, CustomerAccountManagerViewModel _CustomerAccountManagemodel)  
     {  
       var strMessage = string.Empty;  
       Guid EmpID1 = new Guid(pEmpID1);  
       Guid EmpID2 = new Guid(pEmpID2);  
       DateTime TodayDate = DateTime.Now;  
       try  
       {  
         foreach (var item in _CustomerAccountManagemodel.ManagerList.Where(m => m.SelectStatus == true))  
         {  
           IList<DJBL_tblCustomerAccountManagerAssignRelease> listCustomerAccountManagerAssign1 = _billingCommonservice.BillingUnit.CustomerAccountManagerAssignReleaseRepository.Get(d => d.GEmployeeGenInfoID == item.GEmployeeGenInfoID).ToList();  
           DJBL_tblCustomerAccountManagerAssignRelease custAssRelease = null;  
           // Assign Release Insert  
           foreach (var CustAssignRelease in listCustomerAccountManagerAssign1)  
           {  
             custAssRelease = new DJBL_tblCustomerAccountManagerAssignRelease();  
             custAssRelease.CustomerAccountManagerAssignReleaseID = Guid.NewGuid();  
             custAssRelease.CustomerID = CustAssignRelease.CustomerID;  
             custAssRelease.GEmployeeGenInfoID = EmpID2;  
             custAssRelease.AssignDate = TodayDate;  
             custAssRelease.BooketID = CustAssignRelease.BooketID;  
             custAssRelease.ReleaseDate = null;  
             _billingCommonservice.BillingUnit.CustomerAccountManagerAssignReleaseRepository.Add(custAssRelease);  
           }  
           //Assign Release Update   
           foreach (var am in listCustomerAccountManagerAssign1)  
           {  
             am.ReleaseDate = TodayDate;  
             _billingCommonservice.BillingUnit.CustomerAccountManagerAssignReleaseRepository.Update(am, "CustomerAccountManagerAssignReleaseID");  
           }  
           //Transfer responsiblity Insert   
           foreach (var transfer in listCustomerAccountManagerAssign1)  
           {  
             SaveCustomerAccountManagerTransferResponsiblityHistory((Guid)transfer.GEmployeeGenInfoID, EmpID2, TodayDate, (Guid)transfer.BooketID);  
           }  
           _billingCommonservice.BillingUnit.CustomerAccountManagerAssignReleaseRepository.SaveChanges();  
         }  
         return Content(Boolean.TrueString);  
       }  
       catch (Exception ex)  
       {  
         strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Save);  
       }  
       return Content(strMessage);  
     }  


Both Grid binding same i just share one grid binding:


 $("#CustomerAccountManagerKendoGrid1").kendoGrid({  
     dataSource: {  
       transport: {  
         read: "CustomerAccountManageRead"  
       },  
       schema: {  
         model: {  
           fields: {  
             CustomerAccountManageID: { type: "string" },  
             GEmployeeGenInfoID: { type: "string", editable: false },  
             ManagerName: { type: "string", editable: false },  
             SelectStatus: { type: "boolean" },  
           }  
         }  
       },  
       pageSize: 20,  
       serverPaging: false,  
       serverFiltering: false,  
       serverSorting: false,  
     },  
     height: 300,  
     filterable: true,  
     //groupable: true,  
     sortable: true,  
     resizable: true,  
     selectable: true,  
     editable: true,  
     pageable:  
     {  
       refresh: true,  
       pageSizes: [10, 20, 40, 60, 80, 100]  
     },  
     columns:  
     [  
       { field: "SelectStatus", title: " ", width: "5%", template: "<input type='checkbox' #= SelectStatus ? checked='checked':'' # class='chkbx' />" },  
       { field: "CustomerAccountManageID", title: "CustomerAccountManageID", hidden: true, filterable: false, sortable: false },  
       { field: "GEmployeeGenInfoID", title: "GEmployeeGenInfoID", hidden: true, filterable: false, sortable: false },  
       { field: "ManagerName", title: "Manager Name", width: "35%" },  
     ]  
   });  

Grid load:


  public JsonResult CustomerAccountManageRead()  
     {  
       var models = CustomerAccountManage();  
       return Json(models, JsonRequestBehavior.AllowGet);  
     }     


  private List<AssignManagerViewModel> CustomerAccountManage()  
     {  
       IList<DJBL_uspGetAllAssignManager_Result> dataList = null;  
       dataList = _billingCommonservice.BillingUnit.FunctionRepository.AssignManagerValue().ToList();  
       List<AssignManagerViewModel> seriesList = new List<AssignManagerViewModel>();  
       foreach (var md in dataList)  
       {  
         AssignManagerViewModel obj = new AssignManagerViewModel();  
         obj.GEmployeeGenInfoID = md.GEmployeeGenInfoID ?? Guid.Empty;  
         obj.ManagerName = md.ManagerName;  
         obj.ManagerDesignation = md.ManagerDesignation;  
         obj.ManagerDepartment = md.ManagerDepartment;  
         obj.ManagerEmpID = md.ManagerEmpID;  
         obj.ManagerEmpCardNo = md.ManagerEmpCardNo;  
         obj.NoOfCustomer = Convert.ToInt32(md.NoOfCustomer);  
         seriesList.Add(obj);  
       }  
       var PackageInfoInfoViewModels = seriesList.Select(  
         md => new AssignManagerViewModel  
              {  
                GEmployeeGenInfoID = md.GEmployeeGenInfoID,  
                ManagerName = md.ManagerName,  
                ManagerDesignation = md.ManagerDesignation,  
                ManagerDepartment = md.ManagerDepartment,  
                ManagerEmpID = md.ManagerEmpID,  
                ManagerEmpCardNo = md.ManagerEmpCardNo,  
                NoOfCustomer = md.NoOfCustomer,  
                ActionLink = Common.KendoUIGridActionLinkGenerate("Billing", "CustomerAccountManage", md.GEmployeeGenInfoID.ToString(), true, true, false)  
              }).OrderBy(o => o.ManagerName).ThenBy(ot => ot.ManagerEmpID);  
       return PackageInfoInfoViewModels.ToList();  
     }  


Thank you.


Ensure that this project has Microsoft.Bcl.Build installed and packages.config is located next to the project file

In my Xamarin form application their was dependency Restclient on Microsoft.Bcl.Build Microsoft.Bcl. i just remove all using nuget and ...