Friday, June 12, 2009

procedure in mysql

CREATE PROCEDURE `rtest`.`inpair` (in id int,in lev int)

BEGINDECLARE r int;

DECLARE l int;

select rman into r from tblmancount where regId=id and level=lev and month = month(curdate()) and year =year(curdate());

select lman into l from tblmancount where regId=id and level=lev and month = month(curdate()) and year =year(curdate());

if r

insert into tblpair values(id,lev,r,month(curdate),year(curdate));

elsei

insert into tblpair values(id,lev,l,month(curdate),year(curdate));

end if;

END

Thursday, June 11, 2009

Trigger

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER trigger [tgcom] ON [dbo].[tblTabInfo] after insert
as
declare @foid as varchar(50)
declare @com as decimal(20,2)
declare @qu varchar(10)
select @com=(select focash from tblTableInfo where tableID =(select distinct(tableID) from tblTabInfo where fo_id='0353F1'))
select @qu=(select q_no from tblquarter where getdate() between start_date and end_date )
select @foid= fo_id from inserted
insert into tblcommision_details values (@foid,getdate(),@com,@qu)
update tblcommision set amount=convert(decimal(20,2),amount)+ @com where emp_code=@foid and q_id=@qu
begin
exec focommison @foid, @com
end

Procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER procedure [dbo].[focommison](@foid varchar(50),@amt decimal(20,2))
as begin
declare @id varchar(50)
declare @qu varchar(10)
select @id = (select fo_id from tblfcm where emp_code in(select emp_code from tblFO where fo_id=@foid))
select @qu=(select q_no from tblquarter where getdate() between start_date and end_date )
declare @com decimal(20,2)
select @com=@amt*20/100
if @id is not null
begin
print @id
insert into tblcommision_details values (@id,getdate(),@com,@qu)
update tblcommision set amount=convert(decimal(20,2),amount)+ @com where emp_code=@id and q_id=@qu
exec focommison @id,@com
end
end

Wednesday, April 29, 2009

Send attachment through java mail

For run this code you should download mail.jar
http://mirrors.ibiblio.org/pub/mirrors/maven/ant/jars/ant-javamail-1.6.jar

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class Main
{
public static void main (String args[]) throws Exception
{
String host = "mail.xyz.com"; //Host name should be some mail host name
String from = "sounak@xyz.com"; // form address
String to = "sounak@xyz.com"; // to address
String fileAttachment = "d:\\sqljdbc.jar"; // file path
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session session = Session.getInstance(props, null);
// Define message MimeMessage message = new MimeMessage(session); message.setFrom( new InternetAddress(from));
message.addRecipient( Message.RecipientType.TO, new InternetAddress(to)); message.setSubject( "Hello JavaMail Attachment");
// create the message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
//fill message
messageBodyPart.setText("Hi");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fileAttachment); messageBodyPart.setDataHandler( new DataHandler(source)); messageBodyPart.setFileName(fileAttachment);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send( message );
}
}

Monday, April 27, 2009

Java script browser detection and movable div

//browser detection

var agt=navigator.userAgent.toLowerCase(); var is_major = parseInt(navigator.appVersion); var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

//movable div
function initToolTips()
{
if(document.getElementById)
{
toolTipSTYLE = document.getElementById("toolTipLayer").style;
}
if(is_ie is_nav6up)
{
toolTipSTYLE.visibility = "visible";
toolTipSTYLE.display = "none";
document.onmousemove = moveToMousePos;
}
}
function moveToMousePos(e)
{
if(!is_ie)
{ x = e.pageX; y = e.pageY; }
else
{ x = event.x + document.body.scrollLeft; y = event.y + document.body.scrollTop;
}
toolTipSTYLE.left = x + offsetX+'px';
toolTipSTYLE.top = y + offsetY+'px';
return true;
}
function hide()
{ if(is_nav4) toolTipSTYLE.visibility = "hidden";
else toolTipSTYLE.display = "none";
}
function show()
{ toolTip(s);
}
function toolTip(msg, fg, bg)
{
if(toolTip.arguments.length < 1)
// if no arguments are passed then hide the tootip
{ if(is_nav4)
toolTipSTYLE.visibility = "hidden";
else toolTipSTYLE.display = "none";
} else
// show { var content = msg; if(is_nav4)
{ toolTipSTYLE.document.write(content);
toolTipSTYLE.document.close();
toolTipSTYLE.visibility = "visible"; }
else if(is_ie is_nav6up)
{ document.getElementById("toolTipLayer").innerHTML = content; toolTipSTYLE.display='block'; }
}
}

////Above java script is to create the moveable div
//add this code into your page

// add this to any control to your page
onmouseout="hide();" onmouseover="initToolTips();doImage('image name or text');show();

Logout Funda

response.addHeader("Cache-Control", "max-age = 0, s-maxage = 0,must-revalidate, proxy-revalidate, no-cache, no-store ");
response.addHeader("Pragma", "no-cache");


Place the code in the head of the every page.Log out function work properly.