Tuesday 2 April 2013

Search Elements in Array List

// ------ Search elements in ArrayList ---------------- 


package arraylist;

import java.util.ArrayList;

public class SearchAnElementInArrayListExample {
public static void main(String args[]){
ArrayList arraylist= new ArrayList();
arraylist.add("5");
arraylist.add("10");
arraylist.add("1");
arraylist.add("4");
arraylist.add("8");
arraylist.add("3");
arraylist.add("9");
arraylist.add("2");
boolean found = arraylist.contains("40");
System.out.println("Does ArrayList contains 4 "+found);
int index = arraylist.indexOf("80");
if(index == -1)
System.out.println("element 80 not found...");
else
System.out.println("element 80 found...");
int lastindex = arraylist.lastIndexOf("9");
if(lastindex== -1)
System.out.println("element 9 not exist...");
else
System.out.println("element 9 is exist");
}

}

Menu bar with HTML and CSS code


<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CSSnewbie Example: CSS-Only Dropdown Menu</title>
<style>
/* These styles just pretty up the page a bit. */
body {
   font: 62.5%/1.2 Arial, Helvetica, sans-serif;
   background-color: #eee; }
#wrap {
   font-size: 1.3em;
   width: 500px;
   padding: 20px;
   margin: 0 auto; 
   background-color: #;
   position: relative; }

/* These styles create the dropdown menus. */
#navbar {
   margin: 0;
   padding: 0;
   height: 1em; }
#navbar li {
   list-style: none;
   float: left; }
#navbar li a {
   display: block;
   padding: 3px 8px;
   background-color: #5e8ce9;
   color: #fff;
   text-decoration: none; }
#navbar li ul {
   display: none; 
   width: 10em; /* Width to help Opera out */
   background-color: #69f;}
#navbar li:hover ul, #navbar li.hover ul {
   display: block;
   position: absolute;
   margin: 0;
   padding: 0; }
#navbar li:hover li, #navbar li.hover li {
   float: none; }
#navbar li:hover li a, #navbar li.hover li a {
   background-color: #69f;
   border-bottom: 1px solid #fff;
   color: #000; }
#navbar li li a:hover {
   background-color: #8db3ff; }
</style>

<script>

<!-- http://ramsis-code.blogspot.in/  -->
sfHover = function() {
   var sfEls = document.getElementById("navbar").getElementsByTagName("li");
   for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onmouseover=function() {
         this.className+=" hover";
      }
      sfEls[i].onmouseout=function() {
         this.className=this.className.replace(new RegExp(" hover\\b"), "");
      }
   }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>

</head>
<body>
   <div id="wrap">
  
      <ul id="navbar">
      <!-- The strange spacing herein prevents an IE6 whitespace bug. -->
         <li><a href="#">Item One</a><ul>
            <li><a href="#">Subitem One</a></li><li>
            <a href="#">Second Subitem</a></li><li>
            <a href="#">Numero Tres</a></li></ul>
         </li>
         <li><a href="#">Second Item</a>
            <ul>
               <li><a href="#">Just one subitem</a></li></ul>
         </li>
         <li><a href="#">No Subitem</a></li>
         <li><a href="#">Number Four</a>
            <ul>
               <li><a href="#">Subitem One</a></li><li>
               <a href="#">Second Subitem</a></li><li>
               <a href="#">Numero Tres</a></li><li>
               <a href="#">Fourth Thinger</a></li></ul>         
         </li>
      </ul>
      
   </div>

</body>
</html>

SQL Procedure example code



------------- CREATE PROCEDURE EXAMPEL ---------------------

create proc sp_CRUD_AdminTable
(
@id int = null,
@name varchar(50)=null,
@lname varchar(50)=null,
@phone bigint =null,
@maildata text =  null,
@emailid varchar(50)=null,
@add varchar(100)=null,
@city varchar(50)=null,
@operation varchar(50)

)
as
begin
set nocount on
if @operation = 'insert'
begin
insert into ADMIN_TABLE (ADM_NAME,ADM_LAST_NAME,ADM_PHONE,ADM_MAIL_DATA,ADM_EMAILID,
ADM_CREATED_DATE, ADM_ADDRESS,ADM_CITY) values (@name,@lname,@phone,@maildata,@emailid,GETDATE(),@add,@city)
end
else if @operation = 'update'
begin
update ADMIN_TABLE set ADM_NAME = @name,ADM_LAST_NAME =@lname,ADM_PHONE=@phone,ADM_MAIL_DATA=@maildata, ADM_EMAILID=@emailid, ADM_ADDRESS=@add,ADM_CITY=@city where ADM_ID = @id
end
else if @operation = 'delete'
begin
delete from ADMIN_TABLE where ADM_ID = @id
end
else if @operation = 'select'
begin
select * from ADMIN_TABLE where ADM_ID = @id
end
else if @operation = 'selectall'
BEGIN
select * from ADMIN_TABLE 
END
end


------------- USE ALL OPERATION OF THIS PROCEDURE---------------------


select * from ADMIN_TABLE
sp_CRUD_AdminTable null,'ramsis', 'code', 123456789, 'hello world','rh@gmail.com','noida','noida', 'insert'

sp_CRUD_AdminTable 1,'aman', 'kumar', 9632587412, 'hello world','aman@gmail.com','noida','noida', 'update'

sp_CRUD_AdminTable @operation= 'selectall'

sp_CRUD_AdminTable @operation= 'select', @id = 2


sp_CRUD_AdminTable @operation= 'delete', @id = 0

-----------------------------------------------------------------------------------------
------------------- Create A simple Procedure ------------------


create procedure sp_AmanTest(
@name varchar(50)=null,
@lname varchar(50)=null,
@emailid varchar(50)=null
)
as 
begin 
set nocount on

insert into ADMIN_TABLE (ADM_NAME,ADM_LAST_NAME,ADM_EMAILID) values (@name,@lname,@emailid);

end

sp_AmanTest @name ='Aman', @lname ='kumar', @emailid='aman@gmail.com'


Create A trigger on table Before and after delete events

-------- Create A Trigger on table after Delete events ---------

CREATE TRIGGER trgpo on po

after delete 
as
declare @id int;
declare @name varchar(50);
select @id = d.id from deleted d;
select @name = d.name from deleted d;
insert into pohistory values (@id,@name)

go


-------- Create A Trigger on table before Delete events ---------

for delete
as
declare @id int;
declare @name varchar(50);
select @id = d.id from deleted d;
select @name = d.name from deleted d;
insert into pohistory values (@id,@name)

go

SQL Function Example

 

----------- Scaler Function -------

create function udfSquer(@num1 int)
returns int
as
begin
declare @result int;
set @result = @num1 * 5
return @result

end

select dbo.udfSquer(5)

------------- Table Valued Fucntion ----

create function udfTable(@num1 int)
returns @result table ( Id int)
as
begin
declare @start int =1;
declare @end int =10;
while @start <= @end
begin
insert into @result values (@num1 * @start)
set @start = @start + 1;
end
return
end

select * from dbo.udfTable(15)

Jquery hover dropdown menu with css example


<head>
<title>Jquery hover dropdown menu with css example</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$(".menu").hover(
function() { $(".sub").slideToggle(400); },
function() { $(".sub").hide(); }
);
});
</script>
<style type="text/css">

a{
text-decoration: none;
}
.menu{
font-family: Arial;
color: #515151;
width: 200px;
position: relative;
height: 40px;
text-align:left;
width: 202px;
margin: 0 auto;
}
.menu li a{
color: #515151;
display: block;
padding: 6px 15px;
cursor: pointer;
font-size: 14px;
}
.menu li a:hover{
background: #5c83f5;
color: #fff;
}
.sub{
background: #fff;
position: absolute;
z-index: 2;
width: 200px;
padding: 40px 0 3px;
border-radius: 3px;
box-shadow: 0 2px 4px #ddd;
border: 1px solid #ddd;
display: none;
}
a.hover-link{
width: 190px;
background: #fff;
font-size: 14px;
color: #515151;
position: absolute;
z-index: 110;
display: block;
padding: 10px 0 1px 10px;
height: 28px;
cursor:pointer;
border-radius: 5px 5px 0 0;
font-weight: bold;
border: 1px solid #ddd;
}
.sub-options{
list-style:none;
margin:0px;
padding:0px;
font-size: 11px;
}
</style>
</head>
<body>
<div class='menu'>
<a class='hover-link'>Hover on Menu</a>
<div class='sub'>
<ul class='sub-options'>
<li><a href='#'>Home</a></li>
<li><a href='#'>About</a></li>
<li><a href='#'>Services</a></li>
<li><a href='#'>Contact</a></li>
</ul>
</div>
</div>
</body>
</html>

Monday 1 April 2013

Email Validation with JavaScript and Regular Exression

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
openwin();
return (true)
}
else
alert("Invalid E-mail Address! Please re-enter.");
return (false)
}

function openwin()
{
var e   = document.getElementById('email').value;
myWindow=window.open('','','');
myWindow.document.write("<b>Welcome User!<br/>Your Details are:<br/></b>");
myWindow.document.write("Email: "+e);
}
</script>

</HEAD>
<BODY>
<form onSubmit="return checkEmail(this)">
E-mail Address:<br>
<input type="text" id="email">
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>