Wednesday, December 31, 2014

JQuery-Plugin, JQGrid

JQ Grid is excellent alternative of the ASP.NET GridVIew.
http://www.trirand.net/demo/aspnet/webforms/jqgrid/

title = "My Software Assets";
        var grid = $("#softwaregrid");
        $("#softwaregrid").jqGrid(
                {
                    prmNames: { search: "isSearch", nd: null, rows: "numRows", page: "page", sort: "sortField", order: "sortOrder" },
                    postData: { searchString: '', searchField: '', searchOper: '', hiearchy: JSON.stringify(locselection) },
                    datatype: function (postdata) {
                        if (locselection != "MyAssets")
                        {
                            GetSelections();
                        }
                        //alert(JSON.stringify(locselection));
                        $('#softwaregrid').setGridParam({ postData: { hiearchy: JSON.stringify(locselection)} });
                        mtype: "GET", $.ajax({ url: L_Menu_BaseUrl + "/_layouts/XXX/Pages/SwassetService.aspx/GetReports1SoftwareData",
                            type: "POST",
                            async: false,
                            contentType: "application/json; charset=utf-8",
                            data: JSON.stringify(postdata),
                            dataType: "json",
                            success: function (data, st) {

                                if (st == "success")
                                {
                                    var grid = jQuery("#softwaregrid")[0];
                                    grid.addJSONData(JSON.parse(data.d));
                                }
                            },
                            error: function () { alert("Error with AJAX callback"); }
                        });
                    },
                    jsonReader: { root: "rows", page: "page", total: "totalpages", records: "totalrecords", cell: "cell", id: "id", userdata: "userdata", repeatitems: true },                
                    colNames: ['Select', 'ID', 'Title', 'Description', 'Category', 'Terminal', 'Region', 'Supplier'],                 
                    colModel: [
                    { name: 'Select', index: 'id', search: false, hidden: true },
                    { name: 'ID', index: 'id', search: false, hidden: true },
                                                                                { name: 'Title',width: '140px',index: 'a.SoftwareTitle', searchoptions: { sopt: ['cn'] }, hidden: false },
                   
                                                                                {name: 'Description', width: '290px', index: 'a.Description', search: false },
                                                                                {name: 'Category', width: '80px', index: 'b.Name', searchoptions: { sopt: ['cn']} },
                                                                                { name: 'Terminal', width: '215px', index: 'a.Terminal', search: false },
                                                                                { name: 'Region', width: '50px', index: 'a.Region', search: false },
                                                                                { name: 'Supplier', width: '115px', index: 'e.Name', search: false },
                                                                                //{ name: 'Delete', width: '50px', index: 'Delete', search: false }//Naveed SW
                                                                                ],

                    rowNum: 5,
                    rowList: [5, 10, 30,50,100],//Naveed SW
                    //width: '800px',
                    height: '300px',
                    //scrollOffset: 0,                          
                    autowidth: true,
                                multiselect: true,
                    //autoheight:true,
                    shrinkToFit: false,
                    forceFit: true,
                    pager: jQuery("#softwarePager"),
                    sortname: "a.ID",
                    sortorder: "asc",
                                onSelectRow: function (id, status) {
                               
                                                if (!status)
                                                {
                                                                if ($("#jqg_softwaregrid_" + id)[0].checked)                       //Naveed SW   
                                                                {
                                                                                $("#softwaregrid").jqGrid('setSelection', id,false);
                                                                }
                                                }
                                },                            
                                del : {
                                                                caption: "ff",
                                                                msg: "Delete  record(s)?",
                                                                bSubmit: "Delete",
                                                                bCancel: "Cancel"
                                                },                                            
                    ondblClickRow: function (rowid) {
                        var win = window.open("createasset.aspx?assetid=" + rowid, '_blank');
                        win.focus();
                    },
                    viewrecords: true, caption: title
                }).jqGrid('navGrid', "#softwarePager", { edit: false, add: false, del: true, search: true, refresh: true, closeAfterSearch: true, searchtext: "Filter", refreshtext: "Refresh",deltext:"Delete" , deltitle: "Delete selected row(s)"},{},{},
                                                {
              url: '#',
              onclickSubmit: function (postdata) {
                                                                DeleteSoftwares();
                                                                return {};
             },
                                                 reloadAfterSubmit:true,
                                                 beforeShowForm: function(form)
                                                                {
                                                                  $("#delmodsoftwaregrid")[0].style.left="581px"
                                                                  $("#delmodsoftwaregrid")[0].style.top="220px"
                                                                }
                                                }
                //            ).hideCol('cb');//Naveed SW
                                );
                                $('#softwaregrid').trigger( 'reloadGrid');
    }
function DeleteSoftwares()
{
var swselection = [];
$(".cbox:checkbox:checked").each(function () {/
        swselection.push(this.name.substr(this.name.lastIndexOf("_")+1, this.name.length-1));
    })
var url=location.protocol + "//" + location.host + L_Menu_BaseUrl;

$.ajax(
                {
                    type: "POST",
                    url:L_Menu_BaseUrl + "/_layouts/XXX/Pages/SwassetService.aspx/DeleteSoftwares",
                    data: "{'softwares' : '" + JSON.stringify(swselection)+ "','url' : '" + url + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    cache: false,
                    success: function (msg) {

}
}
);
}

Tuesday, December 30, 2014

Usage of Remote Desktop Connection Manager

Download Remote Desktop Connection Manager from the below link

http://www.microsoft.com/en-GB/download/details.aspx?id=21101
Select the existing remote desktop manager settings file / add PROD server settings and get all the servers under one umbrella.


Monday, December 29, 2014

Call to javascript Function from code behind using ScriptManager.RegisterStartupScript

 protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "staffterminalITstaff", "function GetTerminalITStaff(){return '" + hdnstaffjson.ClientID + "';}", true);
           }
        }
 protected override void OnPreRender(EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(string), "LoadBP", "LoadBP('" + hdnLanguage.ClientID + "','" + ddlLanguage.ClientID + "');", true);

        }

Programmatically registering a client script in the ScriptManager

Registering a client script in the ScriptManager is easy!
ScriptManager.RegisterClientScriptInclude(this.Page, this.Page.GetType(), "jQuery", "/_LAYOUTS/xxx/js/jquery-1.7.2.min.js");

Monday, December 22, 2014

Vmware Player and hyper-V incompatable

Got the below error while running the VM on my laptop which has Windows 8.1












The solution is disable the Hyper-V using the below url.
http://www.eightforums.com/tutorials/42041-hyper-v-enable-disable-windows-8-a.html



Sunday, December 21, 2014

Calling stored procedure from another stored procedure SQL Server


While migrating users in SharePoint, i need to take care of migrating user in custom DB level.
Wrote a below script to upgrade the users with new DOMAIN account name.

ALTER PROCEDURE [DB3].[dbo].[UpdateDomainUser_WithClaim]
(
@oldUser nvarchar(300),
    @newUser nvarchar(300)
    )
AS
BEGIN
....
EXEC [DB1].[dbo].UpdateDomainUser_SP1_WithClaim @oldUser ,@newUser
EXEC [DB2].[dbo].UpdateDomainUser_SP2_WithClaim @oldUser ,@newUser
END

Restore Database using Management Studio Express

Thursday, December 18, 2014

Migrating user accounts from one AD domain to another AD Domain using Powershell

Got the opportunity to migrate the users from one domain to another domain. Users should migrate in Nintex DB too.

$nwcmd = 'C:\Program Files\Nintex\Nintex Workflow 2010\NWAdmin.exe'
$nwarg1 = '-o'
$nwarg2 = 'MigrateUser'
$nwarg3 = '-oldUser'
$nwarg4 = '-newUser'
$errorstatus=$ErrorActionPreference

Add-PSSnapin Microsoft.SharePoint.PowerShell -ea silentlycontinue

$m = [Microsoft.SharePoint.Administration.Claims.SPClaimProviderManager]::Local
Function Get-SPClaim {
    param ([string]$user)
    $claim = New-SPClaimsPrincipal -identity $user -IdentityType "WindowsSamAccountName"
    return $m.EncodeClaim($claim)
}



function MigrateUserOrGroups($migrationType, $csvFile)
{
   #Getting the SPFarm object
   $farm = Get-SPFarm

   Write-Host $migrationType
   #Checking whether the user input the type of Migration as Group
   if($migrationType -eq "Group"){
   Import-Csv $csvFile | ForEach-Object{
      Write-Host "Migrating Group" $_.oldlogin "to" $_.newlogin -ForegroundColor Green
      $farm.MigrateGroup($_.oldlogin, $_.newlogin)
     
       }
      }
     
    #Checking whether the user input the type of Migration as User
    if($migrationType -eq "User")
    {

        Import-Csv $csvFile | ForEach-Object{
       
        $olduser= Get-SPClaim($_.oldlogin);
            $newuser= Get-SPClaim($_.newlogin);
            $oldloginname=$_.oldlogin
            try
            {
                $ErrorActionPreference="stop"
               
                Write-Host $newuser
                Write-Host "Migrating User" $_.oldlogin "to" $_.newlogin -ForegroundColor Green
                $farm.MigrateUserAccount( $olduser, $newuser, $false )
                write-host $nwcmd $nwarg1 $nwarg2 $nwarg3 """$olduser""" $nwarg4 """$newuser"""
                & $nwcmd $nwarg1 $nwarg2 $nwarg3 $olduser $nwarg4 $newuser
               
             }
             catch
             {
                write-host "Exception occured for migrating user"  $oldloginname " Message: $($_.Exception.Message)" -ForegroundColor Red
             }
             finally
             {
                $ErrorActionPreference=$errorstatus
             }
               
        }    
    }
     
   Write-Host "Migration Completed" -ForegroundColor Cyan
 
 
 
}

MigrateUserOrGroups $args[0] $args[1]
Follow below links
http://blogs.msdn.com/b/sowmyancs/archive/2012/01/07/migrate-users-groups-powershell-script.aspx?PageIndex=2
http://sharepoint.stackexchange.com/questions/118424/how-to-migrate-ad-domain-groups-in-sharepoint-2010

Monday, December 15, 2014

The type initializer for 'System.ServiceModel.DiagnosticUtility' threw an exception.

Got this error while configuring the Diagnostics in WCF service.
Environment: VS210 and .NET FREAMEWORK=4.0.

Solution: