Friday, 15 April 2016

IFrame Pass values and Get Value


IFrame pass values and Get Value


1. Parent page.

<script>
    // Here "addEventListener" is for standards-compliant web browsers and "attachEvent" is for IE Browsers.
    var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
    var eventer = window[eventMethod];
    // Now...
    // if
    //    "attachEvent", then we need to select "onmessage" as the event.
    // if
    //    "addEventListener", then we need to select "message" as the event
    var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
    // Listen to message from child IFrame window
    eventer(messageEvent, function (e) {
        alert("from mvc");
        alert(e.data);
        // Do whatever you want to do with the data got from IFrame in Parent form.
    }, false);

</script>

2. Child page/ Iframe page

<script language="javascript">      
        function test()
        {          
            window.parent.postMessage("Hello From IFrame", "*");
        }

    </script>
    <div id="divTest" onclick="test();">
        This is test
    </div>

Friday, 26 June 2015

Import data from csv file to table in via SQL



Import data from csv file to table in via SQL



CREATE TABLE #Demotable(  
 [EmpName] [nvarchar](MAX) NULL,  

 [Email] [nvarchar](MAX) NULL
)


BULK INSERT #Demotable FROM 'C:\demo.csv' WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = ' ')


Make sure csv and table have same fields.

Tuesday, 12 May 2015

Pivot table


 

DECLARE @columns VARCHAR(1000)    

SELECT @columns = COALESCE(@columns + ',[' + cast(Status as varchar) + ']','[' + cast(Status as varchar)+ ']')       
FROM(           
  Select Status From Statuses          
) x     
     
print @columns

DECLARE @query nVARCHAR(4000)     

SET @query = ';with CTE_Result as
(
      select Applications.AppName,Computers.Status
      from Applications
      left join Installations on Installations.AppID = Applications.AppID
      left join Computers on Computers.HostID = Installations.HostID
      WHere AppName=''Adobe AIR''
      --group by Applications.AppName,Computers.Status
)
SELECT * FROM
(
      SELECT * from CTE_Result
) as S PIVOT
( COUNT(Status) FOR [Status] IN ('+ @columns + ')) AS PivotTable'
 print @columns    
EXECUTE(@query)    


Result is 

 

Friday, 1 May 2015

Try catch block in store procedure


CREATE PROCEDURE demoTryCatchTest
AS
BEGIN TRY
    SELECT 1/0
END TRY
BEGIN CATCH
    SELECT ERROR_NUMBER() AS ErrorNumber
     ,ERROR_SEVERITY() AS ErrorSeverity
     ,ERROR_STATE() AS ErrorState
     ,ERROR_PROCEDURE() AS ErrorProcedure
     ,ERROR_LINE() AS ErrorLine
     ,ERROR_MESSAGE() AS ErrorMessage;
END CATCH



Tuesday, 29 April 2014

Fetching Tweets Feed using javascript


Fetching Twetter's Tweets using javascript:


Script Part:

<script>
            /*********************************************************************
            #### Twitter Post Fetcher! ####            ********************************************************************/
var twitterFetcher = function()
{
var d = null; return { fetch: function(a, b) { d = b; var c = document.createElement("script"); c.type = "text/javascript"; c.src = "http://cdn.syndication.twimg.com/widgets/timelines/" + a + "?&lang=en&callback=twitterFetcher.callback&suppress_response_codes=true&rnd=" + Math.random(); document.getElementsByTagName("head")[0].appendChild(c) }, callback: function(a) { var b = document.createElement("div"); b.innerHTML = a.body; a = b.getElementsByClassName("e-entry-title"); d(a) } } } ();

/*
* ### HOW TO USE: ###
* Create an ID:
* Go to www.twitter.com and sign in as normal, go to your settings page.
* Go to "Widgets" on the left hand side.
* Create a new widget for "user timeline". Feel free to check "exclude replies"
* if you dont want replies in results.
* Now go back to settings page, and then go back to widgets page, you should
* see the widget you just created. Click edit.
* Now look at the URL in your web browser, you will see a long number like this:
* 123456789012345678
* Use this as your ID below instead!
*/

twitterFetcher.fetch('123456789012345678', function(tweets) {
// Do what you want with your tweets here! For example:
var x = tweets.length;
var n = 0;
var element = document.getElementById('tweets');

if (x > 0) {
var html = '<ul class="twitter-widget">';
    var tweetscount = 2;
while (n < tweetscount)
    {
if (tweets[n].innerHTML) {
html += '<li><a href="#">@DiveRAID</a> ' + tweets[n].innerHTML + '</li>';
         }
else {
html += '<li><a href="#">@DiveRAID</a> ' + tweets[n].textContent + '</li>';
         }
         n++;
}                   
    html += '</ul>';
}
element.innerHTML = html;
});       
</script>
Body Part:

<div id="tweets"></div>



Wednesday, 23 April 2014

Pagging in MVC




Pagging in MVC

View Side:
At top of the view:

@model PagedList.IPagedList<Properties>

@Html.Partial("_Pager")


_Pager.cshtml:

<div class="pagging">
    <div class="left">
        Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
        of @Model.PageCount
    </div>
    <div class="right">
        @{var action = ViewContext.RouteData.GetRequiredString("action");}
        @if (Model.HasPreviousPage)
        {
            @Html.ActionLink("First", action, new { page = 1,CategoryId =  ViewBag.CategoryId , sortBy = ViewBag.sb, IsLoggedIn = ViewBag.ls, sortOrder = ViewBag.so, Name = ViewBag.Name, Email = ViewBag.mail, Gender = ViewBag.gen, AgeFrom = ViewBag.af, AgeTo = ViewBag.at, CountryLocated = ViewBag.col, CityLocated = ViewBag.cil, IsActive = ViewBag.act, UserImage = ViewBag.pho, CountryCode = ViewBag.cc });
            @Html.Raw(" ");
            @Html.ActionLink("Prev", action, new { page = Model.PageNumber - 1,CategoryId =  ViewBag.CategoryId , sortBy = ViewBag.sb, IsLoggedIn = ViewBag.ls, sortOrder = ViewBag.so, Name = ViewBag.Name, Email = ViewBag.mail, Gender = ViewBag.gen, AgeFrom = ViewBag.af, AgeTo = ViewBag.at, CountryLocated = ViewBag.col, CityLocated = ViewBag.cil, IsActive = ViewBag.act, UserImage = ViewBag.pho, CountryCode = ViewBag.cc });
        }
        else
        {
            <span>First</span>
            @Html.Raw(" ");
            <span>Prev</span>
        }
        @if (Model.HasNextPage)
        {
            @Html.ActionLink("Next", action, new { page = Model.PageNumber + 1,CategoryId =  ViewBag.CategoryId , sortBy = ViewBag.sb, IsLoggedIn = ViewBag.ls, sortOrder = ViewBag.so, Name = ViewBag.Name, Email = ViewBag.mail, Gender = ViewBag.gen, AgeFrom = ViewBag.af, AgeTo = ViewBag.at, CountryLocated = ViewBag.col, CityLocated = ViewBag.cil, IsActive = ViewBag.act, UserImage = ViewBag.pho, CountryCode = ViewBag.cc });
            @Html.Raw(" ");
            @Html.ActionLink("Last", action, new { page = Model.PageCount,CategoryId =  ViewBag.CategoryId , sortBy = ViewBag.sb, IsLoggedIn = ViewBag.ls, sortOrder = ViewBag.so, Name = ViewBag.Name, Email = ViewBag.mail, Gender = ViewBag.gen, AgeFrom = ViewBag.af, AgeTo = ViewBag.at, CountryLocated = ViewBag.col, CityLocated = ViewBag.cil, IsActive = ViewBag.act, UserImage = ViewBag.pho, CountryCode = ViewBag.cc });
        }
        else
        {
            <span>Next</span>
            @Html.Raw(" ");
            <span>Last</span>
        }
    </div>
</div>

Controller Side:

var users = new PostRepository().GetUserPictures(objPro_PictureMaster);
            const int pageSize = 10;
            var pageNumber = (objPro_PictureMaster.page ?? 1);
            ViewBag.TotalUsers = users.Count();
            var enumerable = users as IList<Pro_PostMaster> ?? users.ToList();
            ViewBag.FilteredCount = enumerable.Count();
            ViewBag.CategoryDropDownList = categoryBind(CategoryId);
            return View(enumerable.ToPagedList(pageNumber, pageSize));