Friday, May 20, 2016

How to prevent F12 on webpage?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>


<script>
    $(document).keydown(function (event) {
        if (event.keyCode == 123) {
            return false;
        }
        else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) {
            return false;
        }
    });

    $(document).on("contextmenu", function (e) {
        e.preventDefault();
    });
</script>

Tuesday, March 8, 2016

Create Insert script in sql



--sp_CreateInsertScript 'ntrp.tblreceiptpurposemaster','PurposeStatusId=556',1
CREATE  PROC  procCreateInsertScript (
    @tablename NVARCHAR(256) -- table name
    ,@con NVARCHAR(400) -- condition to filter data
    ,@ignoreIdentityCol bit=0 --indicate if ignore columne with identity
    )
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @sqlstr NVARCHAR(MAX);
    DECLARE @valueStr1 NVARCHAR(MAX);
    DECLARE @colsStr NVARCHAR(MAX);
    SELECT @sqlstr='SELECT ''INSERT '+@tablename;
    SELECT @valueStr1='';
    SELECT @colsStr='(';
    SELECT @valueStr1='VALUES (''+';

    IF RTRIM(LTRIM(@con))=''
        SET @con='1=1';

    SELECT @valueStr1=@valueStr1+col+'+'',''+'
            ,@colsStr=@colsStr+name +','
    FROM (
            SELECT
                        CASE
                        /* xtype=173 'binary'*/WHEN a.xtype =173 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR('+CONVERT(NVARCHAR(4),a.length*2+2)+'),'+a.name +')'+' END'
                        /*xtype=104 'bit'*/WHEN a.xtype =104 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR(1),'+a.name +')'+' END'
                        /*xtype=175 'char'*/WHEN a.xtype =175 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'''N''''''+'+'REPLACE('+a.name+','''''''','''''''''''')' + '+'''''''''+' END'
                        /*xtype=61 'datetime'*/WHEN a.xtype =61 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'''N''''''+'+'CONVERT(NVARCHAR(23),'+a.name +',121)'+ '+'''''''''+' END'
                        /*xtype=106 'decimal'*/WHEN a.xtype =106 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR('+CONVERT(NVARCHAR(4),a.xprec+2)+'),'+a.name +')'+' END'
                        /*xtype=62 'float' */WHEN a.xtype =62 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR(23),'+a.name +',2)'+' END'
                        /*xtype=56 'int'*/WHEN a.xtype =56 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR(11),'+a.name +')'+' END'
                        /*xtype=60 'money'*/WHEN a.xtype =60 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR(22),'+a.name +')'+' END'
                        /*xtype=239 'nchar'*/WHEN a.xtype =239 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'''N''''''+'+'REPLACE('+a.name+','''''''','''''''''''')' + '+'''''''''+' END'
                        /*xtype=108 'numeric'*/WHEN a.xtype =108 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR('+CONVERT(NVARCHAR(4),a.xprec+2)+'),'+a.name +')'+' END'
                        /*xtype=231 'nvarchar'*/WHEN a.xtype =231 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'''N''''''+'+'REPLACE('+a.name+','''''''','''''''''''')' + '+'''''''''+' END'
                        /*xtype=59 'real'*/WHEN a.xtype =59 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR(23),'+a.name +',2)'+' END'
                        /*xtype=58 'smalldatetime'*/WHEN a.xtype =58 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'''N''''''+'+'CONVERT(NVARCHAR(23),'+a.name +',121)'+ '+'''''''''+' END'
                        /*xtype=52 'smallint'*/WHEN a.xtype =52 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR(12),'+a.name +')'+' END'
                        /* xtype=122 'smallmoney'*/WHEN a.xtype =122 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR(22),'+a.name +')'+' END'
                        /*xtype=127 'bigint'*/WHEN a.xtype =127 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR(6),'+a.name +')'+' END'
                        /*xtype=48 'tinyint'*/WHEN a.xtype =48 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR(6),'+a.name +')'+' END'
                        /*xtype=165 'varbinary'*/WHEN a.xtype =165 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'CONVERT(NVARCHAR('+CONVERT(NVARCHAR(4),a.length*2+2)+'),'+a.name +')'+' END'
                        /*xtype=167 'varchar'*/WHEN a.xtype =167 THEN 'CASE WHEN '+a.name+' is null THEN ''NULL'' ELSE '+'''N''''''+'+'REPLACE('+a.name+','''''''','''''''''''')' + '+'''''''''+' END'
                        ELSE '''NULL'''
                        END    AS col
                ,a.colid
                ,a.name
            FROM syscolumns a
            WHERE a.id = object_id(@tablename)
            and a.xtype <>189 and a.xtype <>34 and a.xtype <>35 and a.xtype <>36
            and (columnproperty(a.id, a.name, 'IsIdentity') = 0 OR @ignoreIdentityCol=0)
            ) AS t
    ORDER BY colid;

    SELECT @sqlstr=@sqlstr+left(@colsStr,len(@colsStr)-1)+') '+left(@valueStr1,len(@valueStr1)-3)+')'' AS sql FROM '+@tablename +  ' WHERE 1=1 AND  ' + isnull(@con,'1=1');
    PRINT @sqlstr;
    EXEC( @sqlstr);
    SET NOCOUNT OFF
END

How to hash your binary data that exceed the limit (8000bytes) of input parameter of HASHBYTES in Sql

Introduction

Some times, we store binary data in database and need to hash them in order to get an identifier of the binary data. We know the Sql server has a built-in function to do that, it's HASHBYTES. But it's allowed input values are limited to 8000 bytes. Then how to hash the binary data that exceed 8000 bytes? We know Sql Server can be extended with CLR. Here there are mainly two hash algorithms: MD5 and SHA1. Now let us get started.
Background

You should know the  knowledges on C#, Sql, SHA1, MD5
Using the code

1. In Visual Studio 2015, create a Sql Server Database Project.

2. Add a file with template Sql CLR C# User Dfined Function

3. Add the SHA1 and MD5 method as below in your .cs file

The  C# method code lines of hash binary data using SHA1:
Hide   Shrink   Copy Code

/// <summary>
///  Encrypt data with type [varbinary](max) in sql server using SHA1 then return the encrypted data
/// </summary>
/// <param name="content">Input data you will enterd to encrypt it</param>
/// <returns>Return the encrypted text as hexadecimal string</returns>
[SqlFunction(DataAccess = DataAccessKind.None)]
public static String ComputeSHA1(SqlBytes content)
{
    String hashSHA1 = String.Empty;
    //Create new instance of SHA1 and convert the input data to array of bytes
    SHA1 calculator = SHA1.Create();
    Byte[] buffer = calculator.ComputeHash(content.Stream);
    calculator.Clear();

    //loop for each byte, convert it to hexadecimal string and add it to StringBuilder
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < buffer.Length; i++)
    {
        stringBuilder.Append(buffer[i].ToString("x2"));
    }
    hashSHA1 = stringBuilder.ToString();

    // return hexadecimal string
    return hashSHA1;
}

The  C# method code lines of hash binary data using MD5:


/// <summary>
///  Encrypt data with type [varbinary](max) in sql server using MD5 then return the encrypted data
/// </summary>
/// <param name="content">Input data you will enterd to encrypt it</param>
/// <returns>Return the encrypted text as hexadecimal string</returns>
[SqlFunction(DataAccess = DataAccessKind.None)]
public static String ComputeMD5(SqlBytes content)
{
    String hashMD5 = String.Empty;

    //Create new instance of md5 and convert the input data to array of bytes
    MD5 calculator = MD5.Create();
    Byte[] buffer = calculator.ComputeHash(content.Stream);
    calculator.Clear();

    //loop for each byte, convert it to hexadecimal string and add it to StringBuilder
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < buffer.Length; i++)
    {
        stringBuilder.Append(buffer[i].ToString("x2"));
    }
    hashMD5 = stringBuilder.ToString();

    //return hexadecimal string
    return hashMD5;
}

4. build your project and you will get a dll file in bin directory.

5. Publish your assembly file into your Sql Server database. There are two ways to do this.

    Use the publish tool provided by visual studio. You can generate script file and use the script file to pulish or directly publish it into your database.

    Manually register assembly into your database using Transact-SQL

First, you should ensure to enable CLR in your database. If not, execute the following sql


EXEC sp_configure 'clr enabled',1
go
RECONFIGURE
go

Use this sql to register your assembly as below:


CREATE ASSEMBLY [hashassembly]
    AUTHORIZATION [dbo]
    FROM 'c:\hashassembly.dll' WITH PERMISSION_SET = SAFE;

Create sql functions in your database using the following sql


CREATE FUNCTION [dbo].[ComputeMD5]
(@content VARBINARY (MAX))
RETURNS NVARCHAR (40)
AS
 EXTERNAL NAME [hashassembly].[UserDefinedFunctions].[ComputeMD5]

GO

CREATE FUNCTION [dbo].[ComputeSHA1]
(@content VARBINARY (MAX))
RETURNS NVARCHAR (40)
AS
 EXTERNAL NAME [hashassembly].[UserDefinedFunctions].[ComputeSHA1]

So far, we have finished deploying your assembly into you database, you can call the sql function to use it generate your hash value. For example:


UPDATE [dbo].[Picture]
   SET [HashKey] = dbo.ComputeSHA1([PictureBinary])

Monday, February 22, 2016

DateTime Formatting

DateTime Formatting


DateTime is a structureof value Type like int, double etc. It is available in System namespace and present in mscorlib.dll assembly. It implements interfaces like IComparable, IFormattable, IConvertible, ISerializable, IComparable, IEquatable.

Different users need different kind format date. For instance some users need date like "mm/dd/yyyy", some need "dd-mm-yyyy". So below specifiers will help you to get date in different formats. Let's say current Date Time is "12/8/2015 3:15:19 PM" and as per that you will get output based on specifier.



Specifier Description Output
d Short Date 12/8/2015
D Long Date Tuesday, December 08, 2015
t Short Time 3:15 PM
T Long Time 3:15:19 PM
f Full date and time Tuesday, December 08, 2015 3:15 PM
F Full date and time (long) Tuesday, December 08, 2015 3:15:19 PM
g Default date and time 12/8/2015 15:15
G Default date and time (long) 12/8/2015 15:15
M Day / Month 8-Dec
r RFC1123 date Tue, 08 Dec 2015 15:15:19 GMT
s Sortable date/time 2015-12-08T15:15:19
u Universal time, local timezone 2015-12-08 15:15:19Z
Y Month / Year December, 2015
dd Day 8
ddd Short Day Name Tue
dddd Full Day Name Tuesday
hh 2 digit hour 3
HH 2 digit hour (24 hour) 15
mm 2 digit minute 15
MM Month 12
MMM Short Month name Dec
MMMM Month name December
ss seconds 19
fff milliseconds 120
FFF milliseconds without trailing zero 12
tt AM/PM PM
yy 2 digit year 15
yyyy 4 digit year 2015
: Hours, minutes, seconds separator, e.g. {0:hh:mm:ss} 9:08:59
/ Year, month , day separator, e.g. {0:dd/MM/yyyy} 8/4/2007

Monday, February 15, 2016

Fiscal management far better this year than earlier: CGA

Fiscal management far better this year than earlier: CGA: he government’s fiscal management this financial year has been better than the previous years with expenditure being spread out as opposed to the usual bunching up toward the end of the year, accordin

Thursday, February 11, 2016

Diff Between factory an service in Angular js?

1). Factories are functions that return the object, while services are constructor functions of the object which are instantiated with the new keyword.


angular.module('app').factory('SomeService', function() { return { someFunction: function() {} }; });


angular.module('app').service('SomeService', function() { this.someFunction = function() {}; });

Monday, December 7, 2015

@{
    ViewBag.Title = "Product";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/ui-bootstrap-tpls-0.10.0.min.js"></script>
<link href="~/Scripts/bootstrap.min.css" rel="stylesheet" />
<script src="/Scripts/jquery-1.7.1.js"></script>

<script>
    var appProd = angular.module("appProd", ['ui.bootstrap']);
    appProd.filter('startFrom', function () {
        return function (input, start) {
            if (input) {
                start = +start; //parse to int
                return input.slice(start);
            }
            return [];
        }
    });
    appProd.controller("cntProduct", function ($scope, $http, $timeout, $modal, $log) {
        var catid = 0;
        $scope.list = [];
        $scope.entryLimit = 2;
        debugger;
        $.ajax({
            type: 'GET',
            contentType: 'application/json; charset=utf-8',
            url: '/Home/GetList',
            success: function (data) {
                debugger;
                window.alert(1);
                $scope.list = data;
                $scope.currentPage = 1;
                $scope.entryLimit = 2;
                $scope.filteredItems = $scope.list.length;
                $scope.totalItems = $scope.list.length;
                if (catid == '1') {
                    $scope.bClass = "selected";
                    $scope.mClass = "";
                } else {
                    $scope.bClass = "";
                    $scope.mClass = "selected";
                }
            },
            error: function (response) {
                debugger;
                window.alert(1);
            }
        });

        $scope.setPage = function (pageNo) {
            $scope.currentPage = pageNo;
        };
        $scope.filter = function () {
            debugger;
            $timeout(function () {
                $scope.filteredItems = $scope.filtered.length;
            }, 10);

        };

        $scope.getText = function (obj) {
            debugger;

            return obj.replace(' ', '-').replace('&', '-');
        };



    });
</script>
<div id="scartcontent" class="scartcontent" ng-app="appProd" ng-controller="cntProduct">
    <div class="clr pad10"></div>

    <div class="fright cart">
        <div>
            <span>
                <img src='../../images/card-img.jpg' width="31" height="28" alt="" align="absmiddle" /></span><span> hjuyjuyjuy
                 <a href="ViewBasket" title="go to shopping cart">
                     <img src='../../images/green-chkout.jpg' title="Checkout" alt="" align="absmiddle" class="margL10" />
                 </a>
                </span>
        </div>

    </div>
    <div class="cd-tabs">
        <nav>
            <ul class="cd-tabs-navigation">
                <li style="display: none;"><a class="{{bClass}}" n1111g-click="getProductList('1')">Book</a>
                </li>
                <li><a class="{{mClass}}" ng11111-click="getProductList('2')">Magazine</a>
                </li>
            </ul>
            <!-- cd-tabs-navigation -->
        </nav>
        <ul class="cd-tabs-content">
            <li class="selected">

                <div class="pad5">
                    <div class="fleft pad10">
                        PageSize:                        
                    <select ng-model="entryLimit">
                        <option>2</option>
                        <option>5</option>
                        <option>10</option>
                        <option>20</option>
                        <option>50</option>
                        <option>100</option>
                    </select>
                    </div>
                    <div class="fright pad10">
                        <input type="text" class="add_input2 pad5" ng-model="search" ng-change="filter()" id="txtSearch" placeholder="Search Book/Magazine here" />
                    </div>
                </div>
                <div class="clear"></div>
                <div class="gd-row" align="center">

                    <div class="gd-col gu3" ng-repeat="prod in filtered = (list | filter:{ProductName:search}) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">

                        <div class="product-unit">
                            <div class="center">
                                <a ng-disabled='{{prod.OutOfStock=="0"? false :true }}' ng-href="{{prod.CategoryId}}/{{prod.ProductId}}/PD/{{getText(prod.ProductName)}}">
                                    <img style="width: 103px; height: 142px" ng-src="../../Images/{{ prod.ProductImage}}" /></a>
                            </div>
                            <div class="pu-details">
                                <div class="height35">
                                    {{prod.ProductName}}-  {{prod.ProductSummary}}
                                </div>

                                <div class="pu-price margT8">
                                    <div class="pu-border-top padT5">
                                        <div class="margB5">Rs.{{prod.DisplayProductPrice}}</div>
                                    </div>
                                    <div class="pu-border-top"></div>
                                </div>
                                <div class='{{prod.OutOfStock=="0"? "avalb":"notavalb" }}'>
                                    {{prod.OutOfStock=="0"? "Available":"Out of Stock" }}
                                </div>

                            </div>
                        </div>
                    </div>

                </div>
            </li>
        </ul>
        <div class="clear"></div>
        <div class="col-mid-10" style="background: #fff;">
            <div class="pad5">
                <div class="col-wid-10" ng-show="filteredItems == 0">
                    <h4>No Product found as per Search keyword </h4>
                </div>
            </div>
            <div class="clear"></div>
            <div class="fleft col-mid-10" ng-show="filteredItems > 0">
                <div class="fleft col-wid-3 pad10">
                    {{ "Showing " + (currentPage == 1 ? "1" : ((currentPage - 1) * entryLimit)+1) + " to " +
               ((currentPage * entryLimit) >= filteredItems ? filteredItems : (currentPage * entryLimit))
                 + " of " + filteredItems + " Items";}}
                </div>
                <div class="fright pagination-small margR10">
                    <div pagination="" page="currentPage" on-select-page="setPage(page)"
                        boundary-links="true" total-items="filteredItems" items-per-page="entryLimit"
                        previous-text="&laquo;" next-text="&raquo;">
                    </div>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <div class="disclm">
        <strong>Disclaimer</strong>:- All Magazines listed at this site belongs to Publication Division, Ministry of Info. & Broadcasting, for any product related queries or issues customers will have to contact the ministry at 011-2436 7453, email-id pdjucir@gmail.com  for any product non-delivery / refund / quality or other issues related to the magazines listed here. Office of CGA (BharatKosh Portal Owner) will complete financial transaction related activity only.
    </div>
    <div class="clear"></div>

</div>
<div class="clr pad10"></div>
<div class="clr padB20"></div>