Amoraboti - Program
Rashed - Uz - Zaman (Rasel)
  Home About Me Brainstorming Facebook Fan Page Contact    
  Author
I'm Rz Rasel
From Bangladesh

  Archives
April 2010
May 2010
January 2011
February 2011
January 2012
February 2012
March 2012

  Current
Current Posts

  Previous Posts
d
e
2
B
Php:- Check For Valid Email Address
How To Insert Unicode Values To MySQL Using Java
Multiple Checkbox Select/Deselect JavaScript And j...
Dynamically Add/Remove rows in HTML table using Ja...
Dynamically add button, textbox, input, radio elem...
Changing Form Input (Textbox) Style on Focus using...

  My Link
Islam And We
My Diary (Bangla)
My Diary (English)
My Lyrics (Bangla)
My Lyrics (English)
My Poem (Bangla)
My Poem (English)
My Story (Bangla)
My Story (English)
General Knowledge
Fun And Jokes
Lyrics (Bangla)
Lyrics (English)
Lyrics (Hindi)
Quotations
 
 
  Resizing images with PHP  
  Thursday, April 29, 2010  
 
Resizing images with PHP
The code
/*
* File: SimpleImage.php
* Rz Rasel
*/

class SimpleImage
{
var $image;
var $image_type;
function load($filename)
{
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG )
{
$this->image = imagecreatefromjpeg($filename);
}
elseif( $this->image_type == IMAGETYPE_GIF )
{
$this->image = imagecreatefromgif($filename);
}
elseif( $this->image_type == IMAGETYPE_PNG )
{
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null)
{
if( $image_type == IMAGETYPE_JPEG )
{
imagejpeg($this->image,$filename,$compression);
}
elseif( $image_type == IMAGETYPE_GIF )
{
imagegif($this->image,$filename);
}
elseif( $image_type == IMAGETYPE_PNG )
{
imagepng($this->image,$filename);
}
if( $permissions != null)
{
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG)
{
if( $image_type == IMAGETYPE_JPEG )
{
imagejpeg($this->image);
}
elseif( $image_type == IMAGETYPE_GIF )
{
imagegif($this->image);
}
elseif( $image_type == IMAGETYPE_PNG )
{
imagepng($this->image);
}
}

function getWidth() {

return imagesx($this->image);

}

function getHeight() {

return imagesy($this->image);

}

function resizeToHeight($height) {

$ratio = $height / $this->getHeight();

$width = $this->getWidth() * $ratio;

$this->resize($width,$height);

}

function resizeToWidth($width) {

$ratio = $width / $this->getWidth();

$height = $this->getheight() * $ratio;

$this->resize($width,$height);

}

function scale($scale) {

$width = $this->getWidth() * $scale/100;

$height = $this->getheight() * $scale/100;

$this->resize($width,$height);

}

function resize($width,$height) {

$new_image = imagecreatetruecolor($width, $height);

imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());

$this->image = $new_image;

}

}

?>



Usage

Save the above file as SimpleImage.php and take a look at the following examples of how to use the script.

The first example below will load a file named picture.jpg resize it to 250 pixels wide and 400 pixels high and resave it as picture2.jpg

include('SimpleImage.php');

$image = new SimpleImage();

$image->load('picture.jpg');

$image->resize(250,400);

$image->save('picture2.jpg');

?>

If you want to resize to a specifed width but keep the dimensions ratio the same then the script can work out the required height for you, just use the resizeToWidth function.

include('SimpleImage.php');

$image = new SimpleImage();

$image->load('picture.jpg');

$image->resizeToWidth(250);

$image->save('picture2.jpg');

?>

You may wish to scale an image to a specified percentage like the following which will resize the image to 50% of its original width and height

include('SimpleImage.php');

$image = new SimpleImage();

$image->load('picture.jpg');

$image->scale(50);

$image->save('picture2.jpg');

?>

You can of course do more than one thing at once. The following example will create two new images with heights of 200 pixels and 500 pixels

include('SimpleImage.php');

$image = new SimpleImage();

$image->load('picture.jpg');

$image->resizeToHeight(500);

$image->save('picture2.jpg');

$image->resizeToHeight(200);

$image->save('picture3.jpg');

?>

The output function lets you output the image straight to the browser without having to save the file. Its useful for on the fly thumbnail generation

header('Content-Type: image/jpeg');

include('SimpleImage.php');

$image = new SimpleImage();

$image->load('picture.jpg');

$image->resizeToWidth(150);

$image->output();

?>

The following example will resize and save an image which has been uploaded via a form

if( isset($_POST['submit']) ) {

include('SimpleImage.php');

$image = new SimpleImage();

$image->load($_FILES['uploaded_image']['tmp_name']);

$image->resizeToWidth(150);

$image->output();

$image->save( rand( 1, 999999 ) . '_rz.jpg');

} else {

?>







form>

}

?>



Ref: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php

Ref: http://www.gnu.org/licenses/gpl.html



class SimpleImage

{

var $image;

var $image_type;



function load( $filename )

{

$image_info = GetImageSize( $filename );

$this->image_type = $image_info[ 2 ];

if( $this->image_type == IMAGETYPE_JPEG )

{

$this->image = imagecreatefromjpeg( $filename );

} elseif( $this->image_type == IMAGETYPE_GIF )

{

$this->image = imagecreatefromgif( $filename );

}

elseif( $this->image_type == IMAGETYPE_PNG )

{

$this->image = imagecreatefrompng( $filename );

}

}

function save( $filename, $image_type = IMAGETYPE_JPEG, $compression=75, $permissions = null )

{

if( $image_type == IMAGETYPE_JPEG )

{

imagejpeg( $this->image,$filename,$compression );

}

elseif( $image_type == IMAGETYPE_GIF )

{

imagegif( $this->image,$filename );

}

elseif( $image_type == IMAGETYPE_PNG )

{

imagepng( $this->image,$filename );

}

if( $permissions != null)

{

chmod( $filename, $permissions );

}

}

function output( $image_type=IMAGETYPE_JPEG )

{

if( $image_type == IMAGETYPE_JPEG )

{

imagejpeg( $this->image );

}

elseif( $image_type == IMAGETYPE_GIF )

{

imagegif( $this->image );

}

elseif( $image_type == IMAGETYPE_PNG )

{

imagepng( $this->image );

}

}

function getWidth()

{

return imagesx( $this->image );

}

function getHeight()

{

return imagesy( $this->image );

}

function resizeToHeight($height)

{

$ratio = $height / $this->getHeight();

$width = $this->getWidth() * $ratio;

$this->resize( $width,$height );

}

function resizeToWidth($width)

{

$ratio = $width / $this->getWidth();

$height = $this->getheight() * $ratio;

$this->resize($width,$height);

}

function scale($scale)

{

$width = $this->getWidth() * $scale/100;

$height = $this->getheight() * $scale/100;

$this->resize( $width,$height );

}

function resize( $width,$height )

{

$new_image = imagecreatetruecolor( $width, $height );

imagecopyresampled( $new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight() );

$this->image = $new_image;
}

}

?>

Usage

Save the above file as SimpleImage.php and take a look at the following examples of how to use the script.

The first example below will load a file named picture.jpg resize it to 250 pixels wide and 400 pixels high and resave it as picture2.jpg

1
2
3
4
5
6
7




include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resize(250,400);
$image->save('picture2.jpg');
?>

If you want to resize to a specifed width but keep the dimensions ratio the same then the script can work out the required height for you, just use the resizeToWidth function.


include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToWidth(250);
$image->save('picture2.jpg');
?>

You may wish to scale an image to a specified percentage like the following which will resize the image to 50% of its original width and height


include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->scale(50);
$image->save('picture2.jpg');
?>

You can of course do more than one thing at once. The following example will create two new images with heights of 200 pixels and 500 pixels


include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToHeight(500);
$image->save('picture2.jpg');
$image->resizeToHeight(200);
$image->save('picture3.jpg');
?>

The output function lets you output the image straight to the browser without having to save the file. Its useful for on the fly thumbnail generation


header('Content-Type: image/jpeg');
include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToWidth(150);
$image->output();
?>

The following example will resize and save an image which has been uploaded via a form


if( isset($_POST['submit']) ) {

include('SimpleImage.php');
$image = new SimpleImage();
$image->load($_FILES['uploaded_image']['tmp_name']);
$image->resizeToWidth(150);
$image->output();
} else {

?>









}
?>
 
  posted by Rz Rasel At 10:46 PM, ,  
     
  JavaScript Blinking Title  
  Sunday, April 25, 2010  
 
<script typee="text/javascript">

function titlebar(val)

{

var msg = "Your message here --- hscripts.com";

var speed = 500;

var pos = val;

var msg1 = " ****** "+msg+" ******";

var msg2 = " ------- "+msg+" -------";


if(pos == 0){

masg = msg1;

pos = 1;

}

else if(pos == 1){

masg = msg2;

pos = 0;

}


document.title = masg;

timer = window.setTimeout("titlebar("+pos+")",speed);

}


titlebar(0);

</script>

<!-- Script by Rz Rasel -->

<!-- emailtorasel@yahoo.com -->

<!-- more scripts @ http://www.hscripts.com -->

Labels:

 
  posted by Rz Rasel At 12:23 PM, ,  
     
  JavaScript Scrolling Title  
   
 
<script type="text/javascript">

var rev = "fwd";

function titlebar(val)

{

var msg = "Your message here *** hscripts.com";

var res = " ";

var speed = 100;

var pos = val;

msg = " |--- "+msg+" ---|";

var le = msg.length;

if(rev == "fwd"){

if(pos < le){

pos = pos+1;

scroll = msg.substr(0,pos);

document.title = scroll;

timer = window.setTimeout("titlebar("+pos+")",speed);

}

else{

rev = "bwd";

timer = window.setTimeout("titlebar("+pos+")",speed);

}

}

else{

if(pos > 0){

pos = pos-1;

var ale = le-pos;

scrol = msg.substr(ale,le);

document.title = scrol;

timer = window.setTimeout("titlebar("+pos+")",speed);

}

else{

rev = "fwd";

timer = window.setTimeout("titlebar("+pos+")",speed);

}

}

}


titlebar(0);

</script>

<!-- Script by Rz Rasel -->

<!-- emailtorasel@yahoo.com -->

<!-- more scripts @ http://www.hscripts.com -->

Labels:

 
  posted by Rz Rasel At 12:19 PM, ,  
     
  JavaScript Ad Display  
   
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Rz Rasel</title>

<!-- Script by Rz Rasel -->

<script type="text/javascript">

var browserName=navigator.appName;

var left_align = 268; // Set the left position to center the greybox

var top_align = 134; // Set the top position to center the greybox

function disp(){

if(browserName == "Netscape"){

var stop = document.documentElement.scrollTop;

document.getElementById('ebox1').style.height=document.body.offsetHeight+"px";

document.getElementById('s').style.position = "fixed";

}else{

var stop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;

window.onscroll=mveditbox;

}

document.getElementById('s').style.display = 'block';

document.getElementById('ebox1').style.display='block';



document.getElementById('frm').style.opacity = 5/10;

document.getElementById('frm').style.filter = 5/10;

document.getElementById('ebox1').style.zIndex=100;

document.getElementById('s').style.zIndex=1000;

document.getElementById('ebox1').style.top=stop+"px";


var top_pos = stop+top_align;

document.getElementById('s').style.top= top_pos+"px";


var sleft = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;

var left_pos = sleft+left_align;

document.getElementById('s').style.left= left_pos+"px";

}


function hide(){

document.getElementById('s').style.display='none';

document.getElementById('frm').style.opacity = 100;

document.getElementById('ebox1').style.display='none';

}



function mveditbox() {

var stop =window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;

document.getElementById('ebox1').style.top=stop+"px";



var tot = stop+top_align;

document.getElementById('s').style.top= tot+"px";


document.getElementById('ebox1').style.height = document.body.clientHeight+"px";

}

</script>

<!-- Script by Rz Rasel -->


</head>


<body>


<iframe frameborder=1 id='ebox1' width=100%

height=100% bgcolor=#808080 style='display: none; position:absolute;

top: 0px; left: 0px;filter:alpha(opacity=0.5);-moz-opacity: 0.5;opacity: 0.5;background-color: #808080;'>

</iframe>


<form name=frm>

<table id=frm align=center border=0 cellpadding=0 cellspacing=0 bgcolor=black style="border: 1px solid black;">

<tr><td align=left><img src="coding_coding.jpg" onmouseover='disp();'></td></tr></table></form>


<div id='s' style='display: none; border:thin solid black; position: absolute; background-color: black;'>

<div style="background: url('hgreybox/head.gif'); width: 350px; text-align: right; color: white; font-weight: bold;">

<a style='cursor:pointer;color:#ffffff;' onclick='hide()'><b>X </b></a></div>

<div align=center id='ad' style="color: red; background-color: white; font-weight: bold; font-family: Times New Roman; font-size: 14px;"><a style="text-decoration:none;" href="http://hscripts.com/tutorials/photoshop/" target=_blank><img src="ferrari.gif" width=350px></a></div>

</div>
</body>


</html>

Labels:

 
  posted by Rz Rasel At 12:15 PM, ,  
     
  JavaScript Tool Tip  
   
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Rz Rasel</title>

<style type = "text/css">

#bubble_tooltip{

width:210px;

position:absolute;

display: none;

}

#bubble_tooltip .bubble_top{

position:relative;

background-image: url(htooltip/bubble_top.gif);

background-repeat:no-repeat;

height:18px;

}

#bubble_tooltip .bubble_middle{

position:relative;

background-image: url(htooltip/bubble_middle.gif);

background-repeat: repeat-y;

background-position: bottom left;

}

#bubble_tooltip .bubble_middle div{

padding-left: 12px;

padding-right: 20px;

position:relative;

font-size: 11px;

font-family: arial, verdana, san-serif;

text-decoration: none;

color: red;

text-align:justify;

}

#bubble_tooltip .bubble_bottom{

background-image: url(htooltip/bubble_bottom.gif);

background-repeat:no-repeat;

height:65px;

position:relative;

top: 0px;

}

</style>



<!-- Script by Rz Rasel -->


<script type="text/javascript">

var text1="Hi! <br> I am Rasel <br> The tooltip is an easy way of interaction for the visitors in a web page ";

var text2="For webhosting, please contact at eamiltorasel@yahoo.com";


//This is the text to be displayed on the tooltip.


if(document.images){

pic1= new Image();

pic1.src='htooltip/bubble_top.gif';

pic2= new Image();

pic2.src='htooltip/bubble_middle.gif';

pic3= new Image();

pic3.src='htooltip/bubble_bottom.gif';

}


function showToolTip(e,text){

if(document.all)e = event;

var obj = document.getElementById('bubble_tooltip');

var obj2 = document.getElementById('bubble_tooltip_content');

obj2.innerHTML = text;

obj.style.display = 'block';

var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);

if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0;

var leftPos = e.clientX-2;

if(leftPos<0)leftPos = 0;

obj.style.left = leftPos + 'px';

obj.style.top = e.clientY-obj.offsetHeight+2+st+ 'px';

}

function hideToolTip()

{

document.getElementById('bubble_tooltip').style.display = 'none';

}


</script>

<!-- Script by Rz Rasel -->

</head>


<body>

<br>

<br>

<br><br>

<br>

<br>

<!-- Script by Rz Rasel -->


<table id="bubble_tooltip" border=0 cellpadding=0 cellspacing=0>

<tr class="bubble_top"><td></td></tr>

<tr class="bubble_middle"><td><div id="bubble_tooltip_content"></div></td></tr>

<tr class="bubble_bottom"><td colspan=5></td></tr>

</table>


Just move your mouse cursor over the button or image.<br><br>


<input type="button" id="b1" value="BUTTON" onmouseover="showToolTip(event,text1)" onmouseout="hideToolTip()"></input>

<br><br>


<a href="#" onmouseover="showToolTip(event,text2)" onmouseout="hideToolTip()"> LINK </a>


<!-- Script by Rz Rasel -->

</body>

</html>

Pictures:-

Labels:

 
  posted by Rz Rasel At 12:01 PM, ,  
     
  Fixed Bar At The Bottom Like Facebook  
  Saturday, April 10, 2010  
 
FIXED BAR AT THE BOTTOM LIKE FACEBOOK:

<!DOCTYPE HTML>

<html>

<head>

<title>Using CSS Fixed Position Across Browsers</title>

<style type="text/css">



html,

body {

margin: 0px 0px 0px 0px ;

padding: 0px 0px 0px 0px ;

}



#site-body-container {}



#site-body-content {

padding: 15px 15px 15px 15px ;

}



#site-bottom-bar {

background-color: #F0F0F0 ;

border-top: 1px solid #CCCCCC ;

bottom: 0px ;

font-family: verdana, arial ;

font-size: 11px ;

height: 30px ;

position: fixed ;

width: 100% ;

z-index: 1000 ;

}



#site-bottom-bar-frame {

height: 30px ;

margin: 0px 10px 0px 10px ;

position: relative ;

}



#site-bottom-bar-content {

padding: 3px 0px 0px 0px ;

}



#menu-root {

background-color: #E8E8E8 ;

border: 1px solid #D0D0D0 ;

color: #000000 ;

display: block ;

height: 22px ;

line-height: 22px ;

text-align: center ;

text-decoration: none ;

width: 105px ;

}



#menu-root:hover {

background-color: #666666 ;

border-color: #000000 ;

color: #FFFFFF ;

}



#menu {

background-color: #E8E8E8 ;

border: 1px solid #666666 ;

bottom: 32px ;

display: none ;

left: 0px ;

padding: 5px 5px 1px 5px ;

position: absolute ;

width: 200px ;

}



#menu a {

background-color: #E8E8E8 ;

border: 1px solid #FFFFFF ;

color: #000000 ;

display: block ;

margin-bottom: 4px ;

padding: 5px 0px 5px 5px ;

text-decoration: none ;

}



#menu a:hover {

background-color: #666666 ;

border-color: #000000 ;

color: #FFFFFF ;

}



/* -------------------------------------------------- */

/* -- IE 6 FIXED POSITION HACK ---------------------- */

/* -------------------------------------------------- */



html,

body,

#site-body-container {

_height: 100% ;

_overflow: hidden ;

_width: 100% ;

}



#site-body-container {

_overflow-y: scroll ;

_overflow-x: hidden ;

_position: relative ;

}



/* To make up for scroll-bar. */

#site-bottom-bar {

_bottom: -1px ;

_position: absolute ;

_right: 16px ;

}



/* To make up for overflow left. */

#site-bottom-bar-frame {

_margin-left: 26px ;

}



/* To fix IE6 display bugs. */

#menu a {

_display: inline-block ;

_width: 99% ;

}



</style>

<script type="text/javascript" src="jquery-1.3.2.js"></script>

<script type="text/javascript">



jQuery(function( $ ){

var menuRoot = $( "#menu-root" );

var menu = $( "#menu" );



// Hook up menu root click event.

menuRoot

.attr( "href", "javascript:void( 0 )" )

.click(

function(){

// Toggle the menu display.

menu.toggle();



// Blur the link to remove focus.

menuRoot.blur();



// Cancel event (and its bubbling).

return( false );

}

)

;



// Hook up a click handler on the document so that

// we can hide the menu if it is not the target of

// the mouse click.

$( document ).click(

function( event ){

// Check to see if this came from the menu.

if (

menu.is( ":visible" ) &&

!$( event.target ).closest( "#menu" ).size()

){



// The click came outside the menu, so

// close the menu.

menu.hide();



}

}

);



});



</script>

</head>

<body>



<div id="site-bottom-bar" class="fixed-position">

<div id="site-bottom-bar-frame">

<div id="site-bottom-bar-content">



<a id="menu-root" href="##">Toggle Menu</a>



<div id="menu">

<a href="##">Here is a menu item</a>

<a href="##">Here is a menu item</a>

<a href="##">Here is a menu item</a>

<a href="##">Here is a menu item</a>

<a href="##">Here is a menu item</a>

<a href="##">Here is a menu item</a>

</div>



</div>

</div>

</div>





<!-- ------- -->

<!-- ------- -->





<div id="site-body-container">

<div id="site-body-content">



<cfloop

index="i"

from="1"

to="20"

step="1">



<p>

Lorem ipsum dolor sit amet, consectetur

adipiscing elit. Aliquam dictum enim in mauris

luctus convallis. Aliquam erat volutpat.

Suspendisse potenti. Duis blandit, urna vitae

feugiat porttitor, risus est ornare metus, at

dignissim urna velit id enim. Donec lectus nisi,

consectetur eget sollicitudin id, bibendum

laoreet velit.

<p>



</cfloop>



</div>

</div>



</body>

</html>

RZ RASEL
Amoraboti
IF ERROR – PLEASE ACKNOWLEDGE ME. (RZ RASEL)

Labels:

 
  posted by Rz Rasel At 8:21 AM, ,  
     
  Fixed Bar At The Bottom Like Facebook  
   
 

FIXED BAR AT THE BOTTOM LIKE FACEBOOK:

<style type='text/css'>

#bottom_nav

{

position: fixed;

bottom: 0px;

border: 1px solid black;

}

</style>

<div id='bottom_nav'>RZ RASEL - AMORABOTI</div>

RZ RASEL
Amoraboti
IF ERROR – PLEASE ACKNOWLEDGE ME. (RZ RASEL)

Labels:

 
  posted by Rz Rasel At 8:07 AM, ,  
     
  Connect to MySQL using C# and Connector/Net  
  Friday, April 9, 2010  
 
Connect to MySQL using C# and Connector/Net

This is really quite simple. All you need to do is download Connector/Net which is a fully-managed ADO.NET driver written in 100% pure C#. Download the installer and install Connector/Net. After installation load your C# IDE. Begin a new console project.

The first thing you need to do is add a reference to your project. Open the Add Reference dialog box. Under the .Net tab scroll down to MySQL.Data and add this reference to your project. Before we start with the actual code we need to add two namespaces. Add the following namespaces.

using MySql.Data.MySqlClient;
using MySql.Data.Types;

Finally now time to write some code. When connecting to any database you usually need to set up a provider. This provder is of type string and simply consists of information such as database to connect to, username, password and url/name of the machine in which the database is hosted. This provider sring is different for different databases. The provider string needed to connect to a MySQL database is listed below.

string strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;

In the provider string above we simply supply the data source, which is the url/ip/name of the computer which the database is hosted on. We also supply the database name to connected to and the username and password.

If your using a default MySQL installation, the username should be and the password should be the password you used in the installation process.

After setting up a provider, you need to create a connection to the database. You do this by using the MySqlConnection object.

When creating an instance of MySqlConnection, you supply the provider in it’s constructor.

MySqlConnection mysqlCon = new MySqlConnection(strProvider);

We then use the Open() method of mysqlCon object to open a connection to the database.

MySqlConnection mysqlCon = new MySqlConnection(strProvider);
mysqlCon.Open();

Now that the connection is open, you need to query the database. You need to send an SQL statement to get the results from the database. This is done using the MySqlCommand object. In the constructor of the MySqlCommand you supply an SQL statement and also the connection object.

string strSQL = "SELECT * FROM [Your Table Here]";
MySqlCommand mysqlCmd = new MySqlCommand(strSQL,mysqlCon);

So now you can send an SQL statement to the database. But you need a way to store the records, for this you use the MySqlDataReader object.

MySqlDataReader mysqlReader = mysqlCmd.ExecuteReader();

Now the MySqlDataReader object will contain all the records from the database. The MySqlDataReader object is a read only onject, which allows you to quickly get records out of a database table. It can not be used to update a database table.

To get records from the MySqlDataReader object you use a while loop. The loop uses the MySqlDataReader objects Read() method, to get the data for each row.

while (mysqlReader.Read())
{

Console.WriteLine(mysqlReader.GetInt32(0) + "\t" + mysqlReader.GetString(1) + "\t" + mysqlReader.GetString(2));
}

Finally you use the appropriate methods of the MySqlDataReader object to get the data from each column. For example the first column is returned as an Integer using the GetInt32() method, while the second and third columns return string data.

Rz Rasel

Amoraboti

If Error – Please Acknowledge Me. (Rz Rasel)

Labels:

 
  posted by Rz Rasel At 11:26 PM, ,  
     
  Send Email (smtp.gmail.com) Using C Sharp  
  Monday, April 5, 2010  
 
SEND EMAIL (SMTP.GMAIL.COM) USING C SHARP:

The Microsoft .NET framework provides two namespaces, System.Net and System.Net.Sockets for managed implementation of Internet protocols that applications can use to send or receive data over the Internet . SMTP protocol is using for sending email from C#. SMTP stands for Simple Mail Transfer Protocol . C# using System.Net.Mail namespace for sending email . We can instantiate SmtpClient class and assign the Host and Port . The default port using SMTP is 25 , but it may vary different Mail Servers .

The following C# source code shows how to send an email from a Gmail address using SMTP server. The Gmail SMTP server name is smtp.gmail.com and the port using send mail is 587 and also using NetworkCredential for password based authentication.

  SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
  SmtpServer.Port = 587;
  SmtpServer.Credentials =

new System.Net.NetworkCredential("username", "password");

using System;
using System.Windows.Forms;
using System.Net.Mail;
 
namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
 
                mail.From = new MailAddress("your_email_address@gmail.com");
                mail.To.Add("to_address@mfc.ae");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";
 
                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;
 
                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

Rz Rasel

AMORABOTI

If Error – Please Acknowledge Me. (Rz Rasel)
HELP LINK

Labels:

 
  posted by Rz Rasel At 10:06 PM, ,  
     
  Making CSS Rollover Buttons  
   
 

THE MARKUP:

The HTML for our button is wonderfully simple. In fact it's just a link with an id, and a span element wrapped around the link text:

<a id="emailUs" href="#" title="Email Us"><span>Email Us</span></a>

We give the link an ID - in this case, "emailUs" - which allows us to style the link via our CSS. We also place the actual link text inside a span element. This means that we can hide the link text with our CSS and display the image instead, yet the link still looks like a regular text link to browsers not using the style sheet - such as a search engine spider or a text-only browser, for example.

Rz Rasel

AMORABOTI

If Error – Please Acknowledge Me. (Rz Rasel)

Labels:

 
  posted by Rz Rasel At 12:55 PM, ,  
     
  Get Local Computer IP Address  
   
 
Get local computer IP address:

Get local computer IP address (C Sharp):

System.Net.dns.GetHostName();

Getting the IP addresses is a little more tricky - as there can be more
than one per host name:

System.Net.IPAddress[] a =
System.Net.Dns.GetHostAddresses(System.Net.Dns.Get HostName());

for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i].ToString());
}

Rz Rasel

Amoraboti

If Error – Please Acknowledge Me. (Rz Rasel)

Labels:

 
  posted by Rz Rasel At 12:11 AM, ,  
     
  Get Local Computer IP Address  
   
 
Get local computer IP address:

Get local computer IP address (C Sharp):

///
/// Gets IP addresses of the local computer
///

public string GetLocalIP()
{
string _IP = null;

// Resolves a host name or IP address to an IPHostEntry instance.
// IPHostEntry - Provides a container class for Internet host address information.
System.Net.IPHostEntry _IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());

// IPAddress class contains the address of a computer on an IP network.
foreach (System.Net.IPAddress _IPAddress in _IPHostEntry.AddressList)
{
// InterNetwork indicates that an IP version 4 address is expected
// when a Socket connects to an endpoint
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
{
_IP = _IPAddress.ToString();
}
}
return _IP;
}

Rz Rasel

Amoraboti

If Error – Please Acknowledge Me. (Rz Rasel)

Labels:

 
  posted by Rz Rasel At 12:08 AM, ,  
     
  Find Difference Between Two Dates In C Sharp  
  Sunday, April 4, 2010  
 

find difference between two dates in C Sharp


Code Sample: find difference between two dates.


// Start date
DateTime startDate = new DateTime(2005, 2, 1, 3, 4, 12, 56);
// End date
DateTime endDate = new DateTime(2005, 12, 12, 4, 30, 45, 12);
// Time span
TimeSpan diffDate = endDate.Subtract ( startDate );
// Spit it out
Console.WriteLine( "Time Difference: ");
Console.WriteLine(diffDate.Days.ToString() + " Days");
Console.WriteLine(diffDate.Hours.ToString() + " Hours" );
Console.WriteLine(diffDate.Minutes.ToString() + " Minutes");
Console.WriteLine(diffDate.Seconds.ToString() + " Seconds ");
Console.WriteLine(diffDate.Milliseconds.ToString() + " Milliseconds ");

Back Main

Labels:

 
  posted by Rz Rasel At 3:22 AM, ,  
     
  Calculating Date Difference in C Sharp  
   
 

Calculating Date Difference in C Sharp

Code Sample: Calculating the Date Difference - Subtract Method.


using System;
using System.Collections.Generic;
using System.Text;

namespace Console_DateTime
{
class Program
{
static void Main(string[] args)
{
System.DateTime dtTodayNoon = new System.DateTime(2006, 9, 13, 12, 0, 0);
System.DateTime dtTodayMidnight = new System.DateTime(2006, 9, 13, 0, 0, 0);
System.TimeSpan diffResult = dtTodayNoon.Subtract(dtYestMidnight);
Console.WriteLine("Yesterday Midnight - Today Noon = " + diffResult.Days);
Console.WriteLine("Yesterday Midnight - Today Noon = " + diffResult.TotalDays);
Console.ReadLine();
}
}
}
Back Main

Labels:

 
  posted by Rz Rasel At 3:15 AM, ,  
     
  Without SSL connection, Normal SMTP Java  
  Saturday, April 3, 2010  
 

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;
public class AttachExample {
public static void main (String args[]) throws Exception
{
System.getProperties().put("proxySet","true");
System.getProperties().put("socksProxyPort","1080");
System.getProperties().put("socksProxyHost","192.168.155.1");
Properties props = System.getProperties();

String from = "xxxxx@spymac.com";
String to = "xxxx@yahoo.com";
String filename = "AttachExample.java";


// Get system properties
final String username = "USERNAME";
final String password = "PASSWORD";

props.put("mail.user", username);
props.put("mail.host", "mail.spymac.com");
props.put("mail.debug", "true");
props.put("mail.store.protocol", "pop3");
props.put("mail.transport.protocol", "smtp");


Session session = Session.getDefaultInstance(props,
new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}});

// Define message
Message 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
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("Here's the file");
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
// // Part two is attachment // // Create second body part
messageBodyPart = new MimeBodyPart();
// Get the attachment
DataSource source = new FileDataSource(filename);
// Set the data handler to the attachment
messageBodyPart.setDataHandler(new DataHandler(source));
// Set the filename
messageBodyPart.setFileName(filename);
// Add part two
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message);
}
}

Labels:

 
  posted by Rz Rasel At 12:35 PM, ,  
     
  Fetch Mail through a proxy server (Gmail) Java  
   
 

import java.io.UnsupportedEncodingException;
import java.security.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;

public class GmailFetch {

public static void main(String argv[]) throws Exception {

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

// Get a Properties object
Properties props = System.getProperties();
props.setProperty("proxySet","true");
props.setProperty("socksProxyHost","192.168.155.1");
props.setProperty("socksProxyPort","1080");

props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.port", "995");
props.setProperty("mail.pop3.socketFactory.port", "995");

Session session = Session.getDefaultInstance(props,null);


URLName urln = new URLName("pop3","pop.gmail.com",995,null,
"USERNAME", "PASSWORD");
Store store = session.getStore(urln);
Folder inbox = null;
try {
store.connect();
inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
Message[] messages = inbox.getMessages();
inbox.fetch(messages, profile);
System.out.println("Inbox Number of Message" + messages.length);
for (int i = 0; i < style="color:navy;">{

String from = decodeText(messages[i].getFrom()[0].toString());
InternetAddress ia = new InternetAddress(from);System.out.println("FROM:" + ia.getPersonal()+'('+ia.getAddress()+')');

System.out.println("TITLE:" + messages[i].getSubject());

System.out.println("DATE:" + messages[i].getSentDate());
}
}
finally {
try {
inbox.close(false);
}
catch (Exception e) {
}
try {
store.close();
}
catch (Exception e) {
}
}
}

protected static String decodeText(String text)
throws UnsupportedEncodingException {
if (text == null)
return null;
if (text.startsWith("=?GB") || text.startsWith("=?gb"))
text = MimeUtility.decodeText(text);
else
text = new String(text.getBytes("ISO8859_1"));
return text;
}
}

Labels:

 
  posted by Rz Rasel At 12:33 PM, ,  
     
 
  Problem In Font
Download then zip file unzip and install in your system. Or normal font file just install in your system font folder. Rz Rasel
Bangla Font
Bangla Font

  Find Me In Facebook
 
 

   aaaa
 

   aaaa
 
 
Copyright © 2010 - Amoraboti - Program. ® All right reaserved. Design and developed by:- Rz Rasl