Dotnet Tutorials

1. Mouse Click Event
2. Program For Display Number in Words
3. Data Base Entry Using Binding Navigator

1. Mouse Click Event:
If we want to display some message on mouse left or right click, add following code in head tag-

script language ="javascript"
function rightclick()
{
if(event.button==2)
{
alert("Right Button Pressed");
}
if(event.button==1)
{
alert("Left Button Pressed");
}
}
document.onmousedown = rightclick
/script


2. Program For Display Number in Words:

Code for display number in words is given as follows-
Note:Define all variable globally.

String string1;
String[] a = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

String[] b = { "hundred", "thousand", "lakh", "crore" };

String[] c ={ "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen", };

String[] d ={ "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninty" };

private void button1_Click(object sender, EventArgs e)
{

int val;
val = Convert.ToInt32(textBox1.Text);
label1.Text = convertNumToWord(val);

}

public void display(String s)
{
String t;
t = string1;
string1 = s;
string1 += t;
}

public String convertNumToWord(int number)
{

int c = 1;
int rm;
string1 = "";
while (number != 0)
{
switch (c)
{
case 1:
rm = number % 100;
pass(rm);
if (number > 100 && number % 100 != 0)
{
display("");
}
number /= 100;

break;

case 2:
rm = number % 10;
if (rm != 0)
{
display(" ");
display(b[0]);
display(" ");
pass(rm);
}
number /= 10;
break;

case 3:
rm = number % 100;
if (rm != 0)
{
display(" ");
display(b[1]);
display(" ");
pass(rm);
}
number /= 100;
break;

case 4:
rm = number % 100;
if (rm != 0)
{
display(" ");
display(b[2]);
display(" ");
pass(rm);
}
number /= 100;
break;

case 5:
rm = number % 100;
if (rm != 0)
{
display(" ");
display(b[3]);
display(" ");
pass(rm);
}
number /= 100;
break;

}
c++;
}

return string1;
}


public void pass(int number)
{
int rm, q;
if (number < 10) { display(a[number]); } if (number > 9 && number < 20) { display(c[number - 10]); } if (number > 19)
{
rm = number % 10;
if (rm == 0)
{
q = number / 10;
display(d[q - 2]);
}
else
{
q = number / 10;
display(a[rm]);
display(" ");
display(d[q - 2]);
}
}
}

3. Data Base Entry Using Binding Navigator:

Imports System.Data.OleDb
Public Class Data_Entry_Using_Navigator_At_Run_Time

===GLOBAL DATA DECLARATION =======

Dim constr As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=D:\project\VB_DotNet\Data\mintu.mdb"
Dim str As String = "select * from emp"
Dim con As New OleDbConnection(constr)
Dim cmd As New OleDbCommand()
Dim adap As New OleDbDataAdapter()
Dim ds As New DataSet()
Dim bind As New BindingSource()

=====FORM LOAD EVENT============

Private Sub Data_Entry_Using_Navigator_At_Run_Time_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.Open()
cmd.CommandText = str
cmd.Connection = con
adap.SelectCommand = cmd
adap.Fill(ds)
bind.DataSource = ds.Tables(0)
BindingNavigator1.BindingSource = bind
TextBox1.DataBindings.Add("Text", bind, "fname")
TextBox2.DataBindings.Add("Text", bind, "lname")
TextBox3.DataBindings.Add("Text", bind, "dept")
TextBox4.DataBindings.Add("Text", bind, "sal")
con.Close()
End Sub

============DELETE RECORD==============

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim cb As New OleDbCommandBuilder(adap)
bind.RemoveCurrent()
adap.Update(ds)
End Sub

=============BUTTON FOR ADDING NEW RECORD===============

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bind.AddNew()
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox3.Enabled = True
TextBox4.Enabled = True
End Sub

=========SAVE NEW RECORD TO DATABASE=========

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(adap)
adap.Fill(ds, "emp")
Dim dr As DataRow = ds.Tables("emp").NewRow()
dr.Item("fname") = TextBox1.Text
dr.Item("lname") = TextBox2.Text
dr.Item("dept") = TextBox3.Text
dr.Item("sal") = TextBox4.Text
ds.Tables("emp").Rows.Add(dr)
adap.Update(ds, "emp")
bind.AddNew()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub

============BUTTON FOR EDITING==============

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox3.Enabled = True
TextBox4.Enabled = True
End Sub

==========SAVE EDITED RECORD=============

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(adap)
adap.Fill(ds, "emp")
ds.Tables("emp").Rows(bind.Position).Item("fname") = TextBox1.Text
ds.Tables("emp").Rows(bind.Position).Item("lname") = TextBox2.Text
ds.Tables("emp").Rows(bind.Position).Item("dept") = TextBox3.Text
ds.Tables("emp").Rows(bind.Position).Item("sal") = TextBox4.Text
bind.EndEdit()
adap.Update(ds, "emp")
End Sub
End Class