c# Final Record
c# Final Record
NAME :
REGISTER NO :
COURSE : M.C.A
PAGE
S.NO DATE PROGRAM SIGNATURE
NO
1.
2.
3.
4.
5.
6.
7.
8.
Ex No: 01 Write a program to implement multilevel inheritance. Accept and display data for one
student.
Class: student Data Members: Roll_no, name
DATE: Class: Test Data Members: marks 1, marks 2
Class: Result Data Members: total
Aim:
Algorithm:
1
Program:
using System;
using System.Collections.Generic;using
System.Linq;
using System.Text;
namespace Ex1
{
public class student
{
protected int Roll_no;
protected string name;
}
public class Test : student
{
protected int marks1;
protected int marks2;
}
2
Console.WriteLine("\n Mark-2 :" + base.marks2);
this.total = base.marks1 + base.marks2;
Console.WriteLine("\n Total Marks obtained :" + this.total);
}
}
class Program
{
static void Main(string[] args)
{
Result s1 = new Result();
s1.getDetails();
s1.showDetails();
Console.ReadLine();
}
}
}
3
Output:
Result:
4
Ex No: 02 Demonstrate Use of Virtual and override keyword in C# with a simple Program.
DATE:
Aim:
Algorithm:
5
Program:
Program;
using System;
namespace VirtualExample
{
class Shape
{
public double length=0.0;
public double width =0.0;
public double radius =0.0;
6
class Program
{
static void Main(string[] args)
{
double length,width,radius=0.0;
Console.WriteLine("Enter the Length");
length = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Width");
width = Double.Parse(Console.ReadLine());
Rectangle objRectangle = new Rectangle(length, width);
objRectangle.Area();
Console.WriteLine("Enter the Radius");
radius = Double.Parse(Console.ReadLine());
Circle objCircle = new Circle(radius);
objCircle.Area();
Console.Read();
}
}
}
7
Output:
Result:
8
Ex NO: 03 Write a program to design a simple calculator using windows application.
DATE:
Aim:
Algorithm:
9
Form Design:
10
Program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CalculatorApp
{
public partial class Form1 : Form
{
double FirstNumber;
string Operation;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "1";
}
else
{
textBox1.Text = textBox1.Text + "1";
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "2";
}
else
{
textBox1.Text = textBox1.Text + "2";
}
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "3";
}
else
{
11
textBox1.Text = textBox1.Text + "3";
}
}
private void button4_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "4";
}
else
{
textBox1.Text = textBox1.Text + "4";
}
}
private void button5_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "5";
}
else
{
textBox1.Text = textBox1.Text + "5";
}
}
private void button6_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "5";
}
else
{
textBox1.Text = textBox1.Text + "5";
}
}
private void button7_Click(object sender, EventArgs e)
{
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "7";
}
else
{
textBox1.Text = textBox1.Text + "7";
}
}
private void button8_Click(object sender, EventArgs e)
{
12
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = "8";
}
else
{
textBox1.Text = textBox1.Text + "8";
}
}
private void button9_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" && textBox1.Text != null)
{
textBox1.Text = "9";
}
else
{
textBox1.Text = textBox1.Text + "9";
}
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "0";
}
private void bc_Click(object sender, EventArgs e)
{
textBox1.Text = "0";
}
private void ndot_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + ".";
}
private void bad_Click(object sender, EventArgs e)
{
FirstNumber = Convert.ToDouble(textBox1.Text);
textBox1.Text = "0";
Operation = "+";
}
private void bsub_Click(object sender, EventArgs e)
{
FirstNumber = Convert.ToDouble(textBox1.Text);
textBox1.Text = "0";
Operation = "-";
}
private void bmul_Click(object sender, EventArgs e)
{
FirstNumber = Convert.ToDouble(textBox1.Text);
textBox1.Text = "0";
Operation = "*";
}
13
private void bdiv_Click(object sender, EventArgs e)
{
FirstNumber = Convert.ToDouble(textBox1.Text);
textBox1.Text = "0";
Operation = "/";
}
private void nequal_Click(object sender, EventArgs e)
{
double SecondNumber;
double Result;
SecondNumber = Convert.ToDouble(textBox1.Text);
if (Operation == "+")
{
Result = (FirstNumber + SecondNumber);
textBox1.Text = Convert.ToString(Result);
FirstNumber = Result;
}
if (Operation == "-")
{
Result = (FirstNumber - SecondNumber);
textBox1.Text = Convert.ToString(Result);
FirstNumber = Result;
}
if (Operation == "*")
{
Result = (FirstNumber * SecondNumber);
textBox1.Text = Convert.ToString(Result);
FirstNumber = Result;
}
if (Operation == "/")
{
if (SecondNumber == 0)
{
textBox1.Text = "Cannot divide by zero";
}
else
{
Result = (FirstNumber / SecondNumber);
textBox1.Text = Convert.ToString(Result);
FirstNumber = Result;
}
}
}
}
}
14
Output:
Result:
15
Ex No: 04 CONSIDER the dataset student consisting of following tables:
tbl_course (course ID: int, course name: string)
tbl_student(usn: string, stud name: String, Address: String , Course id: int,
DATE: yr of admsn: int)
Develop suitable windows applications using C#.Net having following options:
a) Entering New Course Details.
b) Display the Course details (in a grid)
Aim:
Algorithm:
16
Form Designs:
17
Program :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form {
SqlConnection con = new SqlConnection("Data Source=DESKTOPFOF4B0D\\SQLEXPRESS;Initial
Catalog=master;Integrated Security=True");
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd=new SqlCommand("insert into TBL_COURSE values(" +
textBox1.Text +",'"+ textBox2.Text + "')",con);
cmd.ExecuteNonQuery();
MessageBox.Show("New Course Entered");
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter da=new SqlDataAdapter("select * from TBL_COURSE",con);
DataTable dt= new DataTable();
da.Fill(dt);
dataGridView1.DataSource=dt;
con.Close( );
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
}
}
}
18
Output :
Result:
19
Ex No : 05 Consider the above dataset student. Develop suitable windows application using C#.Net
a) Enter he Student details.
DATE: b) Display the details the student who have taken admission in a particular year.
Aim:
Algorithm:
20
Form Design:
21
Program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Data Source=DESKTOPFOF4B0D\\SQLEXPRESS;Initial
Catalog=master;Integrated Security=True");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select COURSE_ID from
TBL_COURSE", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
}
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd=new SqlCommand ("insert into TBL_STUDENT
values('"+textBox1.Text+ "','"+textBox2.Text +"','"+textBox3.Text+"',"+
comboBox1.Text+ ","+ textBox4.Text +")",con);
cmd.ExecuteNonQuery();
MessageBox.Show("New Student Entered");
con.Close();
}
22
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
comboBox1.Text = "";
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
dis d = new dis();
d.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class dis : Form
{
SqlConnection con = new SqlConnection("Data Source=DESKTOPFOF4B0D\\SQLEXPRESS;Initial
Catalog=master;Integrated Security=True");
public dis()
{
InitializeComponent();
}
private void dis_Load(object sender, EventArgs e)
{
con.Open();
23
SqlCommand cmd = new SqlCommand("select distinct(YR_OF_AD) from TBL_STUDENT", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
}
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from TBL_STUDENT
whereyr_of_ad="+comboBox1.Text,con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
}
}
24
Output:
Result:
25
Ex No : 06 Create the application using ASP.Net server controls that accepts name,
Password, age, E-Mail id and User id. All the information entry is
compulsory. Password should be reconfirmed. Age should be within 21 to
DATE: 30. Email id should be valid. User should have at least a capital letter and
digit as well as length should be between 7 and 20 characters.
Aim:
Algorithm:
26
27
Program:
Default.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
font-size: xx-large;font-
weight: bold; color:
#FF66CC; text-align:
center;
}
.style2
{
width: 500px; text-align:
center;
}
.style5
{
font-size: x-large;text-
align: center;
}
.style6
{
font-size: x-large;text-
align: right;
}
</style>
</head>
<body>
28
Web Application with Validation<br />
</div>
<div style="text-align:center">
<table class="style2">
<tr>
<td class="style6">
<asp:Label ID="lblUserID" runat="server" Text="Enter User ID"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="txtUID" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtUID" ErrorMessage="Value Required" style="font-size:
x-small"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="txtUID"
ErrorMessage="Enter the valid UserName" style="font-size: x-small"
OnServerValidate="CustomValidator1_ServerValidate"
ClientValidationFunction="CustomValidator1_ServerValidate"></asp:CustomValidator>
</td>
</tr>
<tr>
<td class="style6">
<asp:Label ID="lblPassword" runat="server" Text="Enter Password"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="txtPWD" runat="server"
TextMode="Password"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtPWD" ErrorMessage="Value Required" style="font-
size: x-small"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style6">
<asp:Label ID="lblRpassword" runat="server" Text="Re-Type
Password"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="txtRpwd" runat="server"
TextMode="Password"></asp:TextBox>
29
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtRpwd" ErrorMessage="Value Required" style="font-size: x-
small"></asp:RequiredFieldValidator>
<asp:CompareValidatorID="CompareValidator1"runat="server"
ControlToCompare="txtPWD" ControlToValidate="txtRpwd" ErrorMessage="Check
Password" style="font-size: x-small"></asp:CompareValidator>
</td>
</tr>
<tr>
<td class="style6">
<asp:Label ID="lblUname" runat="server" Text="User Name"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="txtUname" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtUname" ErrorMessage="Value Required" style="font-size: x-
small"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style6">
<asp:Label ID="lblAge" runat="server" Text="Age"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="txtAge" ErrorMessage="Value Required" style="font-size: x-
small"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtAge"
ErrorMessage="RangeValidator" MaximumValue="30" MinimumValue="21" style="font-size: x-
small"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="style6">
<asp:Label ID="lblemailID" runat="server" Text="emailID"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="txtEmailID" runat="server"></asp:TextBox> <br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
30
ControlToValidate="txtPWD" ErrorMessage="Value Required" style="font-size: x-
small"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmailID" ErrorMessage="Correct e-mail format" style="font-size: x-small"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td style="text-align: center" >
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</td>
<td style="text-align: center" >
<asp:Button ID="btnClose" runat="server" Text="Close" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls:
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Pa
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgsargs)
{
string tData = args.Value.ToString().Trim();
args.IsValid = false;
if (tData.Length < 7 || tData.Length > 20) return;
31
foreach (char x in tData)
{
if (x >= 'A' && x <= 'Z')
charCnt++;
if (x >= '0' && x <= '9')
numCnt++;
}
if (charCnt < 1 || numCnt < 1) return;
args.IsValid = true;
}
}
32
Output:
Result:
33
Ex No: 07 Develop a web application using C#.Net and ASP.Net for a Bank.
The bank database should consists of following tables:
DATE:
Aim:
Algorithm:
34
Form Designs.
Master page
35
Programs:
Master Page code Design code:
<%@MasterLanguage="C#"AutoEventWireup="true"CodeFile="MasterPage.master.cs"Inher
its="MasterPa ge"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
<styletype="text/css">
.style1
{
text-align: center;
}
.style2
{
font-family: Arial,Helvetica,sans-serif;
}
.style3
{
font-family: Arial,Helvetica,sans-serif; color: #990000;
}
.style4
{
color: #990000;
}
</style>
</head>
<body>
<formid="form1"runat="server">
<divstyle="height: 79px; background-color: #FFCC00;">
</div>
<divstyle="width: 202px; height: 539px; float:left; background-color: #FF00FF;"
class="style1">
<strong>MENU<br/>
<br/>
</strong><spanclass="style2">
36
<ahref="NewBankEntry.aspx"><strong><spanclass="style4">NewBankEntry</span></strong></a>
</span><strong><br class="style3"/>
<br/>
<brclass="style2"/>
</strong><spanclass="style2">
<ahref="NewBranchEntry.aspx"><strong><spanclass="style4">NewBranchEntry</span></strong></a>
</ span><strong><br class="style3"/>
<br/>
<brclass="style2"/>
</strong><spanclass="style2"><strong><spanclass="style4"><ahref="NewCustomerEntry.as
px">NewCu stomerEntry</a></span></strong></span><br/>
<br/>
<a href="DisplayAllRecordOfBank.aspx"><strong>Display All Record Of
Bank</strong></a><strong><br/>
</strong>
<br/>
<strong>
<ahref="DisplayBranchDetails.aspx">DisplayBranchDetails</a></strong><br/>
<br/>
<ahref="DisplayBalance.aspx">Display Balance</a></div>
<divstyle="height: 542px">
<asp:ContentPlaceHolderid="head"runat="server">
</asp:ContentPlaceHolder>
</div>
<divstyle="height: 48px; background-color: #9933FF;">
</div>
</form>
</body>
</html>
<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup
="true"CodeFil e="NewBankEntry.aspx.cs"Inherits="NewBankEntry"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h2class="style1"style="color: #FF0000">New Bank Entry</h2>
<fieldset>
<tablestyle="width: 59%; height: 96px;"border="0"align="center">
<tr>
<tdstyle="width: 810px; text-align: right"> Bank ID</td>
<tdstyle="width: 578px">
37
<asp:TextBoxID="TextBox1"runat="server"Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<tdstyle="width: 810px; text-align: right">Bank
Name</td>
<tdstyle="width: 578px">
<asp:TextBoxID="TextBox2"runat="server"Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<tdstyle="width: 810px"> </td>
<tdstyle="width: 578px"> </td>
</tr>
<tr>
<tdstyle="width: 810px"> </td>
<tdstyle="width: 578px">
<asp:ButtonID="Button1"runat="server"Text="Submit"Width="100px" style="color:
#FF0000"onclick="Button1_Click"/>
</td>
</tr>
</table>
</fieldset>
</asp:Content>
Aspx code:
using System;
using System.Collections.Generic;
using System.Linq;using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;publicpartialclassNewBankEntry :
System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid Button1_Click(object sender, EventArgs e)
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
con.Open();
38
string query = "insert into tbl_Bank(BankID,BankName)
values("+TextBox1.Text+",'"+TextBox2.Text+"')"; SqlCommand cmd =
newSqlCommand(query,con);
int i = cmd.ExecuteNonQuery(); if (i > 0)
{
Response.Write("<script language='javascript'>alert('insertion successful')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('insertion
failed')</script>");
}
TextBox1.Text = ""; TextBox2.Text = "";
}
}
<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup
="true"CodeFil e="NewBranchEntry.aspx.cs"Inherits="NewBranchEntry"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h1>
 
; &nbs
p; &n bsp;
<spanstyle="color: #FF0000">New Branch Entry</span></h1>
<fieldset>
<tablestyle="width: 75%"align="center">
<tr>
<tdstyle="width: 159px; text-align: right;"> Branch ID</td>
<tdstyle="width: 474px">
<asp:TextBoxID="TextBox1"runat="server"Width="200px"Height="25px"></asp:TextBox>
</td>
</tr>
<tr>
<tdstyle="width: 159px; text-align: right;"> Bank ID</td>
<tdstyle="width: 474px">
<asp:DropDownListID="DropDownList1"runat="server"Width="200px"Height="25px"
DataSourceID="SqlDataSource1"DataTextField="BankID"DataValueField="BankID">
<asp:ListItem>Select Bank ID</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource1"runat="server" ConnectionString="<%$
ConnectionStrings:bankDBConnectionString %>" SelectCommand="SELECT [BankID]FROM
[tbl_Bank]"></asp:SqlDataSource>
39
</td>
</tr>
<tr>
<tdstyle="width: 159px; text-align: right;"> Branch Name</td>
<tdstyle="width: 474px">
<asp:TextBoxID="TextBox2"runat="server"Width="200px"Height="25px"></asp:TextBox>
</td>
</tr>
<tr>
<tdstyle="width: 159px; text-align: right;"> </td>
<tdstyle="width: 474px"> </td>
</tr>
<tr>
<tdstyle="width: 159px; text-align: right;"> </td>
<tdstyle="width: 474px">
&nbs p;
<asp:ButtonID="Button1"runat="server"Text="Submit"BackColor="Red"
Width="100px"onclick="Button1_Click"/>
</td>
</tr>
</table>
</fieldset>
</asp:Content>
Aspx code:
using System;
using System.Collections.Generic;
using System.Linq;using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;publicpartialclassNewBranchEntry :
System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid Button1_Click(object sender, EventArgs e)
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
con.Open();
string query = "insert into tbl_Branch(BranchID,BankID,BranchName) values(" +
40
TextBox1.Text + ","+DropDownList1.SelectedValue+",'" + TextBox2.Text + "')";
SqlCommand cmd = newSqlCommand(query, con); int i = cmd.ExecuteNonQuery();if (i > 0)
{
failed')</script>");
}
TextBox1.Text = ""; TextBox2.Text = "";
}
}
New Customer Entry Design code:
<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup
="true"CodeFil e="NewCustomerEntry.aspx.cs"Inherits="NewCustomerEntry"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h1style="color:
#FF0000"> &
nbsp;
&nbs
p; &nb sp; New Customer
Entry</h1>
<fieldset>
<tablealign="center"style="width: 78%">
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Account Number:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_acc"runat="server"Width="200px"Height="25px"></asp:TextBo x>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Bank ID:</b></td>
<tdstyle="width: 363px">
<asp:DropDownListID="DropDownList_bid"runat="server"Width="200px"
41
Height="25px"DataSourceID="SqlDataSource1"DataTextField="BankID"
DataValueField="BankID">
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource1"runat="server" ConnectionString="<%$
ConnectionStrings:bankDBConnectionString %>" SelectCommand="SELECT [BankID] FROM
[tbl_Bank]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Branch ID:</b></td>
<tdstyle="width: 363px">
<asp:DropDownListID="DropDownList_brachId"runat="server"Width="200px"
Height="25px"DataSourceID="SqlDataSource2"DataTextField="BranchID"
DataValueField="BranchID">
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource2"runat="server" ConnectionString="<%$
ConnectionStrings:bankDBConnectionString %>" SelectCommand="SELECT [BranchID]FROM
[tbl_Branch]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Customer Name:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_custnm"runat="server"Width="200px"Height="25px"></asp:Tex tBox>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Address:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_add"runat="server"Width="200px"Height="25px"></asp:TextBo x>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Contact No:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_Con"runat="server"Width="200px"Height="25px"></asp:TextB ox>
</td>
</tr>
42
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Balance:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_bal"runat="server"Width="200px"Height="25px"></asp:TextBo x>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text -align: right; color: #FF0000;"> </td>
<tdstyle="width: 363px"> </td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;"> </td>
<tdstyle="width: 363px">
&nbs p;
<asp:ButtonID="Button1"runat="server"BackColor="Red"Text="Submit"
Width="100px"onclick="Button1_Click"/>
</td>
</tr>
</table>
</fieldset>
</asp:Content>
Aspx Code:
using System;
using System.Collections.Generic;
using System.Linq
;using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;publicpartialclassNewCustomerEntry :
System.Web.UI.Page
{
protectedvoid Button1_Click(object sender, EventArgs e)
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
con.Open();
string query = "insert into
tbl_Account(AccountNo,BankID,BranchID,CustomerName,Address,ContactNo,Balance)
values("+TextBox_acc.Text+","+DropDownList_bid.SelectedValue+","+DropDownList_brac hId.Selecte
dValue+",'"+TextBox_custnm.Text+"','"+TextBox_add.Text+"',"+TextBox_Con.Text+","+TextBox_bal.
Text+")";
43
SqlCommand cmd = newSqlCommand(query, con); int i = cmd.ExecuteNonQuery();if (i > 0)
{
Response.Write("<script language='javascript'>alert('insertion successful')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('insertionfailed')</script>");
}
TextBox_acc.Text = ""; TextBox_custnm.Text = ""; TextBox_add.Text = "";TextBox_Con.Text =
""; TextBox_bal.Text = "";
}
}
Design code to Display all records of particular bank
<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup
="true"CodeFil e="DisplayAllRecordOfBank.aspx.cs"Inherits="DisplayAllRecordOfBank"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h1>
 
; Display All Record of Particular Bank</h1>
<asp:LabelID="Label1"runat="server"
style="font-weight: 700; text-align: right; color: #FF0000" Text="Select The
Bank"></asp:Label>
:<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"onselectedind
exchanged=" DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<br/>
<br/>
<br/>
<asp:GridViewID="GridView_details"runat="server"BackColor="White"
BorderColor="#CC9966"BorderStyle="None"BorderWidth="1px"CellPadding="4"
style="text-align: center"Width="380px">
<FooterStyleBackColor="#FFFFCC"ForeColor="#330099"/>
<HeaderStyleBackColor="#990000"Font-Bold="True"ForeColor="#FFFFCC"/>
<PagerStyleBackColor="#FFFFCC"ForeColor="#330099"HorizontalAlign="Center"/>
<RowStyleBackColor="White"ForeColor="#330099"/>
<SelectedRowStyleBackColor="#FFCC66"Font-Bold="True"ForeColor="#663399"/>
<SortedAscendingCellStyleBackColor="#FEFCEB"/>
<SortedAscendingHeaderStyleBackColor="#AF0101"/>
<SortedDescendingCellStyleBackColor="#F6F0C0"/>
<SortedDescendingHeaderStyleBackColor="#7E0000"/>
44
</asp:GridView>
<br/>
</asp:Content>
Aspx code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;publicpartialclassDisplayAllRecordOfBank : System.Web.UI.Page
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
SqlDataAdapter da;
SqlCommand cmd;
//string query;
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
string query = "select BankName from tbl_Bank "; cmd = newSqlCommand(query, con);
SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read())
{
DropDownList1.Items.Add(dr[0].ToString());
}
con.Close(); gvBankDetail();
}
}
privatevoid gvBankDetail()
{
try{
con.Open();
string query = "select *from tbl_Bank";
cmd = newSqlCommand(query,con); da = newSqlDataAdapter(cmd);DataSet
ds = newDataSet();
da.Fill(ds); GridView_details.DataSource = ds; GridView_details.DataBind(); con.Close();
}
45
{
con.Open();
string query = "select *from tbl_Bank";
cmd = newSqlCommand(query,con); da = newSqlDataAdapter(cmd);DataSet
ds = newDataSet();
da.Fill(ds); GridView_details.DataSource = ds; GridView_details.DataBind(); con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup
="true"CodeFil e="DisplayBranchDetails.aspx.cs"Inherits="DisplayBranchDetails"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h1>Display Branch Detail</h1>
<asp:LabelID="Label1"runat="server"Text="Select the BankName"></asp:Label>
:<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
46
<br/>
<br/>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
<br/>
</asp:Content>
Aspx code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;publicpartialclassDisplayBranchDetails : System.Web.UI.Page
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
SqlDataAdapter da;
SqlCommand cmd;
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
string query = "select BankName from tbl_Bank "; cmd = newSqlCommand(query, con);
SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read())
{
DropDownList1.Items.Add(dr[0].ToString());
}
con.Close(); gvBankDetail();
}
}
privatevoid gvBankDetail()
{
try{
con.Open();
string query = "select *from tbl_Bank,tbl_Branch where
tbl_Bank.BankID=tbl_Branch.BankID"; cmd = newSqlCommand(query, con);da =
47
newSqlDataAdapter(cmd); DataSet ds = newDataSet();
da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protectedvoid DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
con.Open();
Design Code to display the balance for the entered account number
<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup
="true"CodeFil e="DisplayBalance.aspx.cs"Inherits="DisplayBalance"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<tablestyle="width: 78%; height: 98px; vertical-align: middle; text-align: center;"
align="center">
<tr>
<tdstyle="width: 118px">
Account number </td>
<tdstyle="width: 155px">
<asp:TextBoxID="TextBox1"runat="server"Width="200px"></asp:TextBox>
</td>
48
<td> </td>
</tr>
<tr>
<tdstyle="width: 118px">
Bank ID</td>
<tdstyle="width: 155px">
<asp:DropDownListID="DropDownList1"runat="server"Width="200px">
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<tdstyle="width: 118px">Branch
ID</td>
<tdstyle="width: 155px">
<asp:DropDownListID="DropDownList2"runat="server"Width="200px">
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<tdstyle="width: 118px"> </td>
<tdstyle="width: 155px">
&nbs p;
<asp:ButtonID="Button1"runat="server"Text="Display"Width="100px" onclick="Button1_Click"/>
</td>
<td> </td>
</tr>
</table>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
</asp:Content>
Aspx code:
using System;
using System.Collections.Generic;
using System.Linq;using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
49
publicpartialclassDisplayBalance : System.Web.UI.Page
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
SqlDataAdapter da;
SqlCommand cmd;
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
string query = "select BankID from tbl_Bank "; cmd = newSqlCommand(query, con);SqlDataReader
dr = cmd.ExecuteReader(); while (dr.Read())
{
DropDownList1.Items.Add(dr[0].ToString());
}
con.Close();
}
if (!IsPostBack)
{
con.Open();
string query = "select BranchID from tbl_Branch ";
cmd = newSqlCommand(query, con); SqlDataReader dr = cmd.ExecuteReader(); while(dr.Read())
{
DropDownList2.Items.Add(dr[0].ToString());
}
con.Close();
}
}
protectedvoid Button1_Click(object sender, EventArgs e)
{
con.Open();
string query = "select *from tbl_Account where BranchID=" + DropDownList2.SelectedValue
+ "and BankID=" + DropDownList1.SelectedItem + " and AccountNo=" +TextBox1.Text+"";
cmd = newSqlCommand(query, con); da = newSqlDataAdapter(cmd);DataSet
ds = newDataSet();
da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind();con.Close();
}
}
50
Output:
Reports:
Display all records of particular bank
51
The balance should be displayed for the entered account number.
Result
52
Ex No: 08 To calculate the interest for the Bank database using web services.
DATE:
Aim:
Algorithm:
53
FORM DESIGN:
54
WEB SERVICE :-
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
namespace Simpleinterestservice1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
[WebMethod]
public int Simpleinterest(int P,int n,int r)
{
return (P *n *r)/100;
}
}
}
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
55
}
protected void Button1_Click(object sender, EventArgs e)
{
localhost.Service1 mys = new localhost.Service1();
int P = Convert .ToInt32 (TextBox1 .Text);
int n = Convert .ToInt32 (TextBox2 .Text);
int r = Convert .ToInt32 (TextBox3 .Text);
int interest= mys.Simpleinterest (P,n,r);
TextBox4 .Text = interest .ToString ();
}
}
56
OUTPUT:
Result:
57