Wednesday, 17 April 2013

Blink Color Text Font in HTML through Javascript


This JavaScript function tested in all Browsers like:  IE,Chrome,Firefox,Opera,Safari  

 <script type="text/javascript">

        window.setInterval (BlinkIt, 550);
        window.setInterval (BlinkIt1, 300);
        var color0 = "#1F1FFF";
        var color1 ="#FF3300";
        var color2 ="Orange";
        function BlinkIt () {
            var blink0  = document.getElementById ("blinkdata");
            color0 = (color0 == "#1F1FFF")? "Black" : "#1F1FFF";
            blink0.style.color = color0;

        }
        function BlinkIt1 () {
            var blink1 = document.getElementById("blinkadd");
            color1 = (color1 == "#FF3300")? "Black" : "#FF3300";
            blink1.style.color = color1;  
          }
   
    </script>

   <Strong> <p id="blinkadd"> Welcome in ramsis-code blog </p> </strong>

Tuesday, 16 April 2013

HTML form with Jqurey Validation


<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.23.custom.css" />
<script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script>
<style type="text/css">
       .ui-datepicker
       {
           font-size: 8pt;
           font-family: Verdana;
       }       
</style>
<style type="text/css">
.textn{
font-family : Tahoma,Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size : 12px;
font-style : normal;
font-variant : normal;
color:#000000;
}
input{
border: 1px solid;
background-color: #ffffff;
border-color: #13A9FF;
font-family: verdana;
font-size: 12px;
font-weight: normal;
}
select{
border: 1px solid;
background-color: #ffffff;
border-color: #13A9FF;
font-family: verdana;
font-size: 12px;
font-weight: normal;
}
textarea{
border: 1px solid;
background-color: #ffffff;
border-color: #13A9FF;
font-family: verdana;
font-size: 12px;
font-weight: normal;
}
#trOdd{
background-color: #F4BE2C;
}
#trEven{
background-color: #F4BE2C;
}
#tdCount{
background-color: #F4BE2C;
}
#divBrDetails{r
background-color: White;
display:block;
width:350px;
height:75px;
position:relative;
border: 1px solid #13A9FF;
margin: 2px 2px 2px 2px;
padding: 2px 5px 2px 5px;
font-size: 10px;
font-family: tahoma,Verdana, Geneva, Arial, Helvetica, sans-serif;
font-variant: normal;
font-weight: normal;
color: black;
z-index: 101;
}
.txtsuper{
font-family : Tahoma,Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size : 13px;
font-style : normal;
font-variant : normal;
color: Red;
font-weight: bolder;
}
 </style>

<script type="text/javascript">
$(document).ready(function(){
NumberValidate();
AplhabetsValidate();
$(".require").each(function() {
if($(this).attr('class') === "numeric")
{
NumberValidate();
}
$(this).change(function() {
Validate();
});
});
$("select").each(function() {
$(this).change(function() {
Validate();
});
});
function NumberValidate(){
$(".numeric").each(function() {
$(this).keydown(function (evt){
var charCode = (evt.which) ? evt.which : event.keyCode;
if ((charCode != 8 && charCode !=9)&&(charCode < 37 || charCode >39)&&(charCode < 95 || charCode > 105)&&(charCode < 48 || charCode > 57)&&(charCode !=40)){
var error = "#lbl-"+$(this).attr('id').split('-')[1];
$(error).html('Only Numeric values allowed.');
$(this).css('border-color','red' ).css('border-width','2px');
return false;
}else {
var error = "#lbl-"+$(this).attr('id').split('-')[1];
$(error).html('');
$(this).css('border-color','' ).css('border-width','');
return true;
}      
});  
});
}
<!-- character only event validation  -->
function AplhabetsValidate(){
$(".alphabet").each(function() {
$(this).keydown(function (evt){
var charCode = (evt.which) ? evt.which : event.keyCode;
if ((charCode != 8 && charCode !=9)&&(charCode != 20 && charCode !=46)&&(charCode < 37 || charCode >39)&&(charCode < 65 || charCode > 90)&&(charCode < 97 || charCode > 112)&&(charCode !=32)){
//alert("only digit.");
var error = "#lbl-"+$(this).attr('id').split('-')[1];
$(error).html('Only Alphabets values allowed.');
$(this).css('border-color','red' ).css('border-width','2px');
return false;
}else {
var error = "#lbl-"+$(this).attr('id').split('-')[1];
$(error).html('');
$(this).css('border-color','' ).css('border-width','');
return true;
}      
});
});
}
function Validate()
{
var result = true;
$(".require").each(function() {
if($(this).val() === "")
{
$(this).css('border-color','red' ).css('border-width','2px');
var error = "#lbl-"+$(this).attr('id').split('-')[1];
$(error).html($(this).attr('validate'));
result = false;
}
else
{
$(this).css('border-color','' ).css('border-width','');
var error = "#lbl-"+$(this).attr('id').split('-')[1];
$(error).html('');
}
});
$("select").each(function() {
if($(this).val() === "0")
{
$(this).css('border-color','red' ).css('border-width','2px');
var error = "#lbl-"+$(this).attr('id').split('-')[1];
$(error).html($(this).attr('validate'));
result = false;
}
else
{
$(this).css('border-color','' ).css('border-width','');
var error = "#lbl-"+$(this).attr('id').split('-')[1];
$(error).html('');
}
});
return result;
}
$("#submit").click(function() {
if (Validate() === true)
{
return true;
}
else
{
return false;
}
});

});
</script>
 <form  name="form" id="form">
 <center>
 <table >
 </center>
 <tr>
     <td>
Name:
</td>
        <td>
        <input type ="text" class="alphabet require" name="txt1" id ="txt-firstname" validate="Please enter the first name"/>
<label id="lbl-firstname" style="color:red"></label>
</td>
 </tr>
 <tr>
     <td>
Last Name:
</td>
        <td>
        <input type ="text" class="alphabet require" name="txt2" id ="txt-lastname" validate="Please enter the last name"/>
<label id="lbl-lastname" style="color:red"></label>
</td>
 </tr>
  <tr>
     <td>
Address:
</td>
        <td>
        <input type ="text" class="alphabet" name="txt3" id ="txt-address" validate="Please enter the address"/>
<label id="lbl-address" style="color:red"></label>
</td>
 </tr>
   <tr>
     <td>
Mobile:
</td>
        <td>
        <input type ="text" class="numeric" name="txt5" id ="txt-mobile" validate="Please enter the Mobile"/>
<label id="lbl-mobile" style="color:red"></label>
</td>
 </tr>
   <tr>
     <td>
email id:
</td>
        <td>
        <input type ="text" class="alphabet" name="txt4" id ="txt-email" validate="Please enter the email id"/>
<label id="lbl-email" style="color:red"></label>
</td>
 </tr>
 <tr>
     <td>
 State:
</td>
        <td>
         <select id="ddl-state" name="select1" validate="Please select the state">
 <option value="0">--selest--</option>
<option value="Uttar pradesh">Uttar pradesh</option>
<option value="Bihar">Uttar pradesh</option>
</select>
<label id="lbl-state" style="color:red"></label>
</td>
 </tr>
  <tr>
     <td>
 City:
</td>
        <td>
         <select id="ddl-city" name="select2" validate="Please select the city"> 
 <option value="0">--selest--</option>
<option value="Ghaziabad">Uttar pradesh</option>
<option value="Luclnow">Uttar pradesh</option>
</select>
<label id="lbl-city" style="color:red"></label>
</td>
 </tr> 
 <tr>
     <td>
 <input type="submit" id="submit" name="submit" value="Submit" / >
</td>
        <td>
      <input type="reset" id="reset" name="reset" value="Reset" / >   
</td>
 </tr>
 </table>
 </form>

Thursday, 11 April 2013

Jquery Datepicker with Age count function



<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.23.custom.css" />
<script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script>

<script type="text/javascript">
function cal_age() {
var bday=(document.getElementById("dateofbirth").value);
 
var spl =  bday.split("/");
var bdate = spl[0];
var bmonth = spl[1];
var byear = parseInt(spl[2]);
//alert(byear);
//var bmo=(parseInt(document.getElementById("selMonths").value)-1);
//var byr=parseInt(document.getElementById("selYears").value);
var age;
var now = new Date();
tmo=(now.getMonth());
tday=(now.getDate());
//alert(tday);
var tyr=parseInt(now.getFullYear());
{
if(tyr > byear)
{age=byear}
  else
{age=byear}
document.getElementById("txtApAge").value=(tyr-age);
}
}

</script>

<script type="text/javascript">
$(document).ready(function(){
// $("#dateofbirth").datepicker({ 
 //  dateFormat: 'yy-mm-dd',
//   showAnim: 'slideDown',
// changeMonth: true,
// yearRange: '1950:2012',
// changeYear: true }); 
 $('#dateofbirth').datepicker({
changeMonth: true,
showAnim: 'slideDown',
changeYear: true,
maxDate:0,
dateFormat: 'dd/mm/yy',
      yearRange: '1950:+0'});
});
</script>
<style type="text/css"> 
      .ui-datepicker
       {
           font-size: 8pt;
           font-family: Verdana;
       }       
</style>
  <table>
      <tr id="trOdd">
<td width="15%">
<b>Date of Birth :</b><font size="2" color="#FF0000"> </font>
</td>
<td>
 <input type="text" size="20" name="dateofbirth" id="dateofbirth" readonly="readonly" onchange="cal_age();" maxlength="100" ></input>
</td>
<td width="29%"><B>AGE :</B><font size="2" color="#FF0000"> </font>
<input type="text" name="txtApAge" id="txtApAge" size="5" maxlength="4" readonly />&nbsp;&nbsp;<b></b>
  </td>
</tr>
</table>
<a href="http://jqueryui.com/datepicker/" target="_blank">download datepicker Widgets</a>  


Thursday, 4 April 2013

SQL Cursor Example


     To use cursors in SQL Server, you need to do the following steps:

-- (1) Declare a cursor that defines a result set.
-- (2) Open the cursor to establish the result set.
-- (3)  Fetch the data into local variables as needed from the cursor.
-- (4) Close the cursor when done.
-- (5) Deallocate the cursor.


declare cr2 cursor for select id from fst 
open cr2
fetch from cr2;
close cr2
deallocate cr2

-----------------------------------------------------------
 ---  Use Cursor on a Table 'fst' to featch 'id' column records

declare cr1 cursor for select id from fst 
declare @id int;
open cr1
fetch from cr1 into @id;
while @@FETCH_STATUS = 0
begin
print @id
fetch from cr1 into @id
end
close cr1
deallocate cr1


Create a Cursor to take Backup and Restore of all SQL Server databases

------ Here is an example of CURSOR to take Backup of all SQL Server databases where backups are issued in a serial manner ------

DECLARE @name VARCHAR(50) -- database name  
DECLARE @path VARCHAR(256) -- path for backup files  
DECLARE @fileName VARCHAR(256) -- filename for backup  
DECLARE @fileDate VARCHAR(20) -- used for file name 

SET @path = 'D:\BackUp\'  

SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) 

DECLARE db_cursor CURSOR FOR  
SELECT name 
FROM MASTER.dbo.sysdatabases 
WHERE name NOT IN ('master','model','msdb','tempdb')  

OPEN db_cursor   
FETCH NEXT FROM db_cursor INTO @name   

WHILE @@FETCH_STATUS = 0   
BEGIN   
       SET @fileName = @path + @name + '_' + @fileDate + '.BAK'  
       BACKUP DATABASE @name TO DISK = @fileName  

       FETCH NEXT FROM db_cursor INTO @name   
END   

CLOSE db_cursor   
DEALLOCATE db_cursor


----------- Create a CURSOR to Restore  SQL Server Databases ------------


DECLARE @DBName varchar(255)
DECLARE @DATABASES_Fetch int
DECLARE DATABASES_CURSOR CURSOR FOR
Select DATABASE_NAME = name From sys.sysdatabases
where name in ('Testing','amantrn') order by 1
OPEN DATABASES_CURSOR
FETCH NEXT FROM DATABASES_CURSOR INTO @DBName
WHILE @@FETCH_STATUS = 0
BEGIN
exec ('RESTORE DATABASE ' + @DBName + ' FROM DISK =''D:\BackUp\' + @DBName +'.bak'' WITH REPLACE')
FETCH NEXT FROM DATABASES_CURSOR INTO @DBName
END
CLOSE DATABASES_CURSOR
DEALLOCATE DATABASES_CURSOR




Wednesday, 3 April 2013

File handling though BufferedReader, Bufferwriter Class in java

package com.scannerclass;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class IoEditFileEample {

    public static void main(String[] args) throws IOException {

        File f=new File("E:/Temp/appendOldFile.txt");
        if (!f.exists()) {
   f.createNewFile();
  }
        
        FileInputStream fs = null;
        InputStreamReader in = null;
        BufferedReader br = null;

        StringBuffer sb = new StringBuffer();

        String textinLine;
      
        
        try {
             fs = new FileInputStream(f);
             in = new InputStreamReader(fs);
             br = new BufferedReader(in);

            while(true)
            {
                textinLine=br.readLine();
                if(textinLine==null)
                    break;
                sb.append(textinLine);
            }
              String textToEdit1 = "";
              int cnt1 = sb.indexOf(textToEdit1);
              sb.replace(cnt1,cnt1+textToEdit1.length(),"New Append text");

              String textToEdit2 = "";
              int cnt2 = sb.indexOf(textToEdit2);
              sb.replace(cnt2,cnt2+textToEdit2.length(),"Second new edit text");

              fs.close();
              in.close();
              br.close();

            } catch (FileNotFoundException e) {
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }
            catch (Exception e) {
                e.printStackTrace();
              }

            try{
                FileWriter fstream = new FileWriter(f);
                BufferedWriter outobj = new BufferedWriter(fstream);
                outobj.write(sb.toString());
                outobj.close();

            }catch (Exception e){
              System.err.println("Error: " + e.getMessage());
            }
    }
}

In ArrayList setdata getdata Example in java

//---- You can use this example to understand how to set and get data in java --- //

package aman.sort;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Run {

/**
 * @param args
 */
public static void main(String[] args) {

List dataBean = new ArrayList();
try {
String ch;
do{
DataBean bean = new DataBean();
ch="";
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the User :");
    String name = br.readLine();
    bean.setName(name);
    System.out.println("Enter the Id :");
    int id = (Integer.parseInt(br.readLine()));
    bean.setId(id);
    dataBean.add(bean);
    System.out.println("Press 'y' for input again data... ");
    ch = br.readLine();
}while((ch.equals("y"))||ch.equals("Y"));
}
catch(Exception e) {
System.out.println("Error occured due to input invalid data..."+e);
}
for(Object obj: dataBean) {
DataBean getbean  = (DataBean)obj;
System.out.println("name is :"+getbean.getName()+"Id is:"+getbean.getId());
}

}

}


//=================================================

package aman.sort;

public class DataBean {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}