Sunday, 27 March 2016

How to Add ADO.Net Entity Data Model(.edmx) file with database changes in MVC5?

How to Add ADO.Net Entity Data Model(.edmx) file with database changes in MVC5?

1. Add New Folder names as Entities
2. Right Entity folder ---->Add ----> Add New Item---> Data ------>ADO.net Entity DataModel.
3. Name = > MyEntity ---> Right click Entity.edmx------>choose update modelfrom Browser.
4. Choose EF Designer from Database ---->Next ----> Yes, include the sensitive data.. -----> save connectionstring as FytotEntites -----> Next
5. Choose Table and StoredProcedure---> MyEntity --->Finish.
6. Now Code automatically Generated in MyEntity.Context.cs

How to Update an edmx file with database changes in MVC5?

How to Update an edmx file with database changes in MVC5?

1. In Entity Folder----> open Entity.edmx file
2. Select All and delete all models in the designer.
3. Goto ModelBrowser---> Right click Entity.edmx------>choose update modelfrom Browser.
4. In ADD or Refresh Select Tables and StoredProcedure----->Finish
5. Rebuild project to check your changes.

Thursday, 24 March 2016

How to Generate 6 (Alphanumeric)Digits Random code in MVC and C#

How to Generate 6 (Alphanumeric)Digits Random code in MVC and C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;


public string GenerateVerifyCode()
        {
            int MAX_LENGTH = 6;
            char[] chrarrOTPChars = null;
            string strAlphaNum = null;
            byte[] btarrOTP = null;
            StringBuilder sbOTP = null;

            try
            {
                strAlphaNum = "abcdefghijklmnopqrstuvwxyz1234567890";
                chrarrOTPChars = new char[strAlphaNum.Length];
                chrarrOTPChars = strAlphaNum.ToCharArray();

                btarrOTP = new byte[1];
                RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
                crypto.GetNonZeroBytes(btarrOTP);
                btarrOTP = new byte[MAX_LENGTH];
                crypto.GetNonZeroBytes(btarrOTP);
                sbOTP = new StringBuilder(MAX_LENGTH);
                foreach (byte b in btarrOTP)
                { sbOTP.Append(chrarrOTPChars[b % (chrarrOTPChars.Length - 1)]); }
                return sbOTP.ToString();
            }
            catch (Exception oEx)
            {
                throw oEx;
            }
            finally
            {
                btarrOTP = null;
                strAlphaNum = null;
                chrarrOTPChars = null;
                sbOTP.Length = 0;
                sbOTP = null;
            }
        }

O/P:  6hjk7o
 

Tuesday, 22 March 2016

jQuery

jQuery


What is jQuery?

jQuery is a lightweight, "write less, do more", JavaScript library.
The jQuery library contains the following features:
  • HTML/DOM manipulation
  • CSS manipulation
  • HTML event methods
  • Effects and animations
  • AJAX
  • Utilities

Adding jQuery to Your Web Pages


<script src="jquery-1.12.0.min.js"></script>
OR
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
OR
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.0.min.js"></script>


jQuery Syntax

$(this).hide() - hides the current element.
$("p").hide() - hides all <p> elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".

jQuery Selectors

$("*")
Selects all elements
$("#p")
Selects  id=”p” elements
$(".p")
Selects  class=”p” elements
$(this)
Selects the current HTML element
$("p.intro")
Selects all <p> elements with class="intro"
$("p:first")
Selects the first <p> element
$("ul li:first")
Selects the first <li> element of the first <ul>
$("ul li:first-child")
Selects the first <li> element of every <ul>
$("[href]")
Selects all elements with an href attribute
$("a[target='_blank']")
Selects all <a> elements with a target attribute value equal to "_blank"
$("a[target!='_blank']")
Selects all <a> elements with a target attribute value NOT equal to "_blank"
$(":button")
Selects all <button> elements and <input> elements of type="button"
$("tr:even")
Selects all even <tr> elements
$("tr:odd")
Selects all odd <tr> elements



jQuery Event

Mouse Events
Keyboard Events
Form Events
Document/Window Events
click
keypress
submit
load
dblclick
keydown
change
resize
mouseenter
keyup
focus
scroll
mouseleave

blur
unload


Click()
$("p").click(function(){
  // action goes here!!
});
dblclick()
$("p").dblclick(function(){
    $(this).hide();
});
mouseenter()
$("#p1").mouseenter(function(){
    alert("You entered p1!");
});
mouseleave()
$("#p1").mouseleave(function(){
    alert("Bye! You now leave p1!");
});

Mousedown()

$("#p1").mousedown(function(){
    alert("Mouse down over p1!");
});
mouseup()

$("#p1").mouseup(function(){
    alert("Mouse up over p1!");
});
hover()
$("#p1").hover(function(){
    alert("You entered p1!");
},
function(){
    alert("Bye! You now leave p1!");
});
focus()
$("input").focus(function(){
    $(this).css("background-color", "#cccccc");
});

blur()

$("input").blur(function(){
    $(this).css("background-color", "#ffffff");
});

on()

$("p").on("click", function(){
    $(this).hide();
});
Multiple Function
$("p").on({
    mouseenter: function(){
        $(this).css("background-color", "lightgray");
    },
    mouseleave: function(){
        $(this).css("background-color", "lightblue");
    },
    click: function(){
        $(this).css("background-color", "yellow");
    }
});

jQuery hide() and show()


$("#hide").click(function(){
    $("p").hide();
});

$("#show").click(function(){
    $("p").show();
});

Fullscreen Responsive Slideshow in jQuery

Fullscreen Responsive Slideshow in jQuery

index.html:

<!DOCTYPE>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="js/ajSlider.min.js"></script>
<title>ajSlider jQuery Plugin Example</title>
<style>
body{
    margin:0;
    color:rgb(255,255,255);
}
</style>
<script>
$( document ).ready(function() {
    $('#ajSlider').ajSlider(3000,{
        "width":"100%",//width of slider
        "height":"100%",//height of slider
        "textPosition":"30%",//position of text from top
        "textSize":"60px"//font size of the text
        });
});
</script>
</head>
<body>
<div id="ajSlider">
    <img src="https://unsplash.it/1800/1200?image=1006" />
    <img src="https://unsplash.it/1800/1200?image=1005" />
    <img src="https://unsplash.it/1800/1200?image=1004" />
    <img src="https://unsplash.it/1800/1200?image=1003" />
    <img src="https://unsplash.it/1800/1200?image=1002" />
    <a>first slide in the slider</a>
    <a>second slide in the slider</a>
    <a>third slide in the slider</a>
    <a>fourth slide in the slider</a>
    <a>fifth slide in the slider</a>
    <div id="left"><a>a</a>
        <img src="images/left.png" />
    </div>  
    <div id="right">
        <img src="images/right.png" />
    </div>
</div>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-36251023-1']);
  _gaq.push(['_setDomainName', 'jqueryscript.net']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
</body>
</html>


ajSlider.min.js:



!function(e){e.fn.ajSlider=function(t,i){function l(){c>=a?(c=0,e(r[c]).css({"background-color":i.activeBullet}),e(r[a]).css({"background-color":i.inactiveBullet}),e(o[c]).fadeIn(1e3),e(n[c]).css({top:textpostop+"%"}),e(n[c]).fadeIn(100).animate({top:textposbottom+"%"}),e(o[a]).fadeOut(1e3),e(n[a]).fadeOut(1e3)):(c++,e(r[c]).css({"background-color":i.activeBullet}),e(r[c-1]).css({"background-color":i.inactiveBullet}),e(o[c]).fadeIn(1e3),e(n[c]).css({top:textpostop+"%"}),e(n[c]).fadeIn(100).animate({top:textposbottom+"%"}),e(o[c-1]).fadeOut(1e3),e(n[c-1]).fadeOut(1e3)),"disable"!=i.slideshow&&(s=setTimeout(l,t))}var d={slideshow:"enable",width:"",height:"",textSize:"32px",textPosition:"35%",activeBullet:"black",inactiveBullet:"grey"};i=e.extend(d,i);var s,o=e("#ajSlider").children("img"),n=e("#ajSlider").children("a"),a=o.length-1,c=0;for(slideW=document.getElementById("ajSlider").style.width,slideH=document.getElementById("ajSlider").style.height,z=0;z<=a;z++)jabaW=e(o[z]).width(),jabaH=e(o[z]).height(),jabaW>slideW&&(slideW=e(o[z]).width()),jabaH>slideH&&(slideH=e(o[z]).height());for(slideWtemp=slideW,slideHtemp=slideH,tempH=i.height.replace("%",""),tempW=i.width.replace("%",""),""!=i.width&&(slideW=i.width,i.width.indexOf("%")>-1&&(slideW=innerWidth*tempW/100,slideH=innerWidth/slideWtemp*tempW/100*slideH)),""!=i.height&&(slideH=i.height,i.height.indexOf("%")>-1&&(slideH=innerHeight*tempH/100,slideW=innerHeight/slideHtemp*tempH/100*slideW)),i.height.indexOf("%")>-1&i.width.indexOf("%")>-1&&(slideW=innerWidth*tempW/100,slideH=innerHeight*tempH/100),document.getElementById("ajSlider").style.width=slideW,document.getElementById("ajSlider").style.height=slideH,e(n).css({width:.8*slideW,height:.8*slideH}),e(o).css({width:slideW,height:slideH}),e("#ajSlider").append("<div style='text-align:center'><ul id='ajSliderBullets'></ul></div>"),cnt=0;cnt<=a;cnt++)e("#ajSliderBullets").append("<li id='bullet"+cnt+"'></li>");e(function(){e("#ajSliderBullets li").on("click",function(){var d=this.id.replace("bullet","");clearTimeout(s),e(o[c]).fadeOut(100),e(n[c]).fadeOut(1e3),e(r[c]).css({"background-color":i.inactiveBullet}),e(o[d]).fadeIn(100),e(n[d]).css({top:textpostop+"%"}),e(n[d]).fadeIn(100).animate({top:textposbottom+"%"}),e(r[d]).css({"background-color":i.activeBullet}),c=d,"disable"!=i.slideshow&&(s=setTimeout(l,t))})});var r=e("#ajSliderBullets").children();e(r).css({"background-color":i.inactiveBullet}),e(r[0]).css({"background-color":i.activeBullet}),e("#ajSlider").css({position:"relative",overflow:"hidden","list-style":"none outside none"}),e("#ajSlider img").css({position:"absolute",top:"0px",left:"0px",display:"none"}),e("#ajSlider a").css({"font-size":i.textSize,top:i.textPosition,"padding-left":"10%","padding-right":"10%",position:"absolute",display:"none","text-align":"center"}),e("#ajSliderBullets").css({width:slideW,left:-40,position:"absolute",display:"inline-block",bottom:"5%"}),e("#ajSliderBullets li").css({height:"15px",width:"15px",display:"inline-block","list-style":"none",margin:"10px","border-radius":"10px"});var p=n[0],h=window.getComputedStyle(p),u=h.getPropertyValue("top");textpostop=u.replace("%","")-3,textposbottom=u.replace("%",""),o[0].style.display="block",n[0].style.display="block","disable"!=i.slideshow&&(s=setTimeout(l,t))}}(jQuery);   



Output:



Monday, 21 March 2016

How to Generate Random Number in SQL

Ex 1:    convert(numeric(6,0),rand() * 999999) + 100000    o/p:259746

How to Generate Random Secret key with Number and Alphabet in c#

How to Generate Random Secret key with Number and Alphabet in c# public void randomnumber()
    {
        String guid = "";
        String allowchars = " ";
        allowchars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
        allowchars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
        allowchars += "1,2,3,4,5,6,7,8,9,0";
        char[] sep = { ',' };
        String[] arr = allowchars.Split(sep);
        String temp = "";
        Random rnd = new Random();
        for (int i = 0; i < 8; i++)
        {
            temp = arr[rnd.Next(0, arr.Length)];
            guid += temp;
        }
        number1.Text = guid.ToString();
    }
o/p: Number with Apphabet: 2HjiKG4


How to Generate Random Number(only Numbers) in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
protected void Page_Load(object sender, EventArgs e)
    {
        int ranid = RandomNumber(00000, 9999999);
        number.Text = ranid.ToString();       
    }
    private int RandomNumber(int min, int max)
    {
        Random random = new Random();
        return random.Next(min, max);
    }
o/p:number.Text: 8598736

How to Generate Random Numbers in c#

using System.Security.Cryptography;
using System.Text;
string randomnumber=GetRandomKey(4);

private string GetRandomKey(int len)
{
int maxSize = len;
char[] chars = new char[30];
string a;
a = "1234567890";
chars = a.ToCharArray();
int size = maxSize;
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
crypto.GetNonZeroBytes(data);
size = maxSize;
data = new byte[size];
crypto.GetNonZeroBytes(data);
StringBuilder result = new StringBuilder(size);
 foreach (byte b in data) { result.Append(chars[b % (chars.Length)]); }
return result.ToString();
}
o/p:

5268