[go: up one dir, main page]

0% found this document useful (0 votes)
297 views32 pages

17MCA57 Lab Program

The document contains 9 programming problems in C# covering topics like command line arguments, boxing and unboxing, operator overloading for complex numbers, jagged arrays, exceptions handling, inheritance with virtual and override keywords, delegates, abstract classes and properties. Each problem has the full code for a C# program to demonstrate the relevant concept.

Uploaded by

Achutha JC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
297 views32 pages

17MCA57 Lab Program

The document contains 9 programming problems in C# covering topics like command line arguments, boxing and unboxing, operator overloading for complex numbers, jagged arrays, exceptions handling, inheritance with virtual and override keywords, delegates, abstract classes and properties. Each problem has the full code for a C# program to demonstrate the relevant concept.

Uploaded by

Achutha JC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

17MCA57 .

NET LABORATORY
PART-A
1.(a) Write a Program in C# to demonstrate Command line arguments processing for the following
using System;
using System.Text;
using System.Collections;
using System.Data;
namespace Cons
{
public class squareroot
{
public static void Main()
{
Console.WriteLine("Enter a Number : ");
int Number = Convert.ToInt16(Console.ReadLine());
double SqrtNumber = Math.Sqrt(Number);
Console.WriteLine("Square root of {0} is: {1}", Number, SqrtNumber);
Console.ReadLine();
}
}
}
1.(b) To find the sum & average of three numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Program
{
class Program
{
static void Main(string[] args)
{
int num, sum = 0, r;
Console.WriteLine("Enter a Number : ");
num = int.Parse(Console.ReadLine());
while (num != 0)
{
r = num % 10;
num = num / 10;
sum = sum + r;
}
Console.WriteLine("Sum of Digits of the Number : "+sum);
Console.ReadLine();

}
}
}

2.Write a Program in C# to demonstrate the following


(a) Boxing and UnBoxing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

Page 1
17MCA57 .NET LABORATORY
namespace prg2
{
class Program
{
static void Main(string[] args)
{
int i = 10;
object o = i;
Console.WriteLine("int boxing {0}",o);
int j=(int)o;
Console.WriteLine("int unboxing {0}", j);
long p = 999999;
object k = p;
Console.WriteLine("long boxing {0}", k);
long l = (long)k;
Console.WriteLine("long unboxing {0}", l);
Console.Read();
}
}
}

(b) Invalid unboxing


class TestUnboxing
{
static void Main()
{
int i = 123;
object o = i; // implicit boxing
try
{
int j = (short)o; // attempt to unbox

System.Console.WriteLine("Unboxing OK.");
}
catch (System.InvalidCastException e)
{
System.Console.WriteLine("{0} Error: Incorrect unboxing.", e.Message);
}
}
}

3.Write a program in C# to add Two complex numbers using Operator overloading

using System;

public struct Complex


{
public int real;
public int imaginary;

public Complex(int real, int imaginary)


{
this.real = real;
this.imaginary = imaginary;

Page 2
17MCA57 .NET LABORATORY
}

public static Complex operator +(Complex c1, Complex c2)


{
return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary);
}
public override string ToString()
{
return (String.Format("{0} + {1}i", real, imaginary));
}

public static void Main()


{
Complex num1 = new Complex(2, 3);
Complex num2 = new Complex(3, 4);

Complex sum = num1 + num2;

Console.WriteLine("First complex number: {0}", num1);


Console.WriteLine("Second complex number: {0}", num2);
Console.WriteLine("The sum of the two numbers: {0}", sum);
Console.ReadLine();

}
}

4. Write a Program in C# to find the sum of each row of given jagged array of 3inner arrays
using System;

namespace jag
{
class Program
{
static void Main(string[] args)
{
const int rows = 3;
int i, sum= 0;
int[][] j_arr = new int[rows][];
j_arr[0] = new int[2];
j_arr[1] = new int[3];
j_arr[2] = new int[4];

j_arr[0][1] = 10;
j_arr[1][0] = 20;
j_arr[1][1] = 30;
j_arr[2][0] = 40;
j_arr[2][2] = 50;
j_arr[2][3] = 60;
for (i = 0; i < 2; i++)
sum += j_arr[0][i];
for (i = 0; i < 3; i++)
sum += j_arr[1][i];
for (i = 0; i < 4; i++)
sum += j_arr[2][i];

Page 3
17MCA57 .NET LABORATORY
Console.WriteLine("sum is :{0}",sum);
Console.Read();
}
}
}

5. Write a Program in C# to demonstrate Array Out of Bound Exception using Try, Catch and Finally blocks

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

namespace lab5
{
class DivNumbers
{
int result;
DivNumbers()
{
result = 0;
}
public void division(int num1,int num2)
{
try
{
result = num1 / num2;
}
catch (DivideByZeroException e)
{
Console.WriteLine("Exception caught:{0}", e);
}
finally
{
Console.WriteLine("Result:{0}", result);
}
}
static void Main(string[] args)
{
DivNumbers d = new DivNumbers();
d.division(25, 0);
Console.ReadLine();
}
}
}

6. Write a Program to Demonstrate Use of Virtual and override key words in C# with a simple program

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

Page 4
17MCA57 .NET LABORATORY
namespace lab6
{
class BC
{
public virtual void display()
{
System.Console.WriteLine("BC::Display");
}
}
class DC : BC
{
public override void display()
{
System.Console.WriteLine("DC::Display");
}
class TC : DC
{
public override void display()
{
System.Console.WriteLine("TC::Display");
}
}
class program
{
public static void Main(string[] args)
{
BC b;
b = new BC();
b.display();
b = new DC();
b.display();
b = new TC();
b.display();
Console.ReadLine();
}
}
}
}

7. Write a Program in C# to create and implement a Delegate for any two arithmetic operations

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
delegate int NumberChanger(int n);
namespace lab7
{
class TestDelegate
{
static int num = 10;
public static int AddNum(int p)
{
num += p;
return num;
}

Page 5
17MCA57 .NET LABORATORY
public static int MulNum(int q)
{
num *= q;
return num;
}
public static int getNum()
{
return num;
}
public static void Main(String[] args)
{
NumberChanger nc1 = new NumberChanger(AddNum);
NumberChanger nc2 = new NumberChanger(MulNum);
nc1(25);
Console.WriteLine("value of num:" + getNum());
nc2(5);
Console.WriteLine("value of num:" + getNum());
Console.ReadKey();

}
}
}

8. Write a Program in C# to demonstrate abstract class and abstract methods in C#.


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

namespace ConsoleApplication8
{
abstract class shape
{

protected float r,l,b;


public abstract float Area();
public abstract float Circumference();
}
class Rectangle:shape
{
public void GetLB()
{
Console.Write("Enter length:");
l = float.Parse(Console.ReadLine());
Console.Write("Enter Breadth:");
b = float.Parse(Console.ReadLine());
}
public override float Area()
{
return l*b;
}
public override float Circumference()
{
return 2*(l+b);
}
}

Page 6
17MCA57 .NET LABORATORY
class Circle:shape
{
public void GetRadius()
{
Console.Write("enter radius:");
r=float.Parse(Console.ReadLine());
}
public override float Area()
{
return 3.14f*r*r;
}
public override float Circumference()
{
return 2*3.14f*r;
}
}
class Mainclass
{
public static void Calculate(shape s)
{

Console.WriteLine("Area:"+s.Area());
Console.WriteLine("Circumference:"+s.Circumference());
}
static void Main(string[] args)
{
Rectangle R=new Rectangle();
R.GetLB();
Calculate(R);
Console.WriteLine();
Circle C=new Circle();
C.GetRadius();
Calculate(C);
Console.ReadKey();
}

}
}

9. Write a program to Set & Get the Name & Age of a person using Properties of C# to illustrate the use of
different properties in C#.

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

namespace lab17
{
class student
{
int sno;
string sname;
public int stu_no
{
set
{

Page 7
17MCA57 .NET LABORATORY
sno = value;
}
get
{
return sno;
}
}
public string stu_name
{
set
{
sname = value;
}
get
{
return sname;
}
}
}
class Program
{
static void Main(string[] args)
{
student xx = new student();
xx.stu_no = 054;
xx.stu_name = "sai sree";
Console.WriteLine("student no={0} \n student name={1}", xx.stu_no, xx.stu_name);
Console.Read();
}
}
}

10. Write a Program in C# Demonstrate arrays of interface types (for runtime polymorphism).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
List<Dog> dogs = new List<Dog>();
dogs.Add(new Dog("fido"));
dogs.Add(new Dog("BOb"));
dogs.Add(new Dog("Adam"));
dogs.Sort();
foreach (Dog dog in dogs)
Console.WriteLine(dog.Describe());
Console.ReadKey();

Page 8
17MCA57 .NET LABORATORY
}
interface IAnimal
{
string Describe();
string Name
{
get;
set;
}
}
class Dog : IAnimal, IComparable
{
private string name;
public Dog(string name)
{
this.Name = name;
}
public string Describe()
{
return "Hello I am a Dog and my name is" + this.Name;
}
public int CompareTo(object obj)
{
if (obj is IAnimal)
return this.Name.CompareTo((obj as IAnimal).Name);
return 0;
}
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
}

PART-B

I. Consider the Database db_EMS (Employee Management System)


consisting of the following tables :
tbl_Designations (IdDesignation: int, Designation: string)
tbl_EmployeeDetails(IdEmployee: int, EmployeeName: string, ContactNumber: string, IdDesignation:
int, IdReportingTo: int)
Develop a suitable window application using C#.NET having following options.
1. Enter new Employee details with designation & Reporting Manager.
2. Display all the Project Leaders (In a Grid) reporting to selected Project Managers (In a Combo box).
3. Display all the Engineers (In a Grid) reporting to selected Project Leader (In a Combo box).
4. Display all the Employees (In a Grid) with their reporting Manager (No Value for PM).
NOTE: tbl_Designation is a static table containing the following Rows in it.
1 Project Manager
2 Project Leader

Page 9
17MCA57 .NET LABORATORY
3 Engineer

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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\student\Documents\Visual Studio
2008\Projects\gowtham\WindowsFormsApplication1\WindowsFormsApplication1\Datab
ase1.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
SqlDataAdapter da;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
cmd.Connection = con;
loadlist();

Page 10
17MCA57 .NET LABORATORY
}
public void loadlist()
{
con.Open();
cmd.CommandText = "select * from tbl_designation";
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
comboBox2.Items.Add(dr[1].ToString());
}
}
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
cmd.CommandText = "insert into EmployeeDetails values('" +
textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" +
comboBox1.SelectedItem.ToString() + "','" + textBox5.Text + "')";
cmd.ExecuteNonQuery();
cmd.Clone();
MessageBox.Show("Record inserted");
con.Close();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox5.Text = "";
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs
e)
{
if (comboBox2.SelectedIndex == 0)
{
dt.Reset();
con.Open();
ds.Reset();
ds.Tables.Add(dt);
da = new SqlDataAdapter("select * from EmployeeDetails ",
con);
da.Fill(dt);
dataGridView1.DataSource = dt.DefaultView;
con.Close();
}
else
{
con.Open();
ds.Reset();
ds.Tables.Add(dt);
da = new SqlDataAdapter("select * from EmployeeDetails where
IdDesignation='" + comboBox2.SelectedIndex + "'", con);
da.Fill(dt);
dataGridView1.DataSource = dt.DefaultView;
con.Close();
}

Page 11
17MCA57 .NET LABORATORY
}
}
}

2. Consider the Database db_LSA (Lecturer Subject Allocation) consisting of the following tables:
tbl_Subjects(IdSubject: int, SubjectCode: string, SubjectName: string)
tbl_Lecturers(IdLecturer: int, LecturerName: string, ContactNumber: string)
tbl_LecturerSubjects(IdSubject: int, SubjectCode: string, IdLecturer: int)
Develop a suitable window application using C#.NET having following options.
1. Enter new Subject Details.
2. Enter New Lecturer Details

Page 12
17MCA57 .NET LABORATORY

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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\student\Documents\Visual Studio
2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Database1.mdf
;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
SqlDataAdapter da;
DataSet ds = new DataSet();
DataTable dt = new DataTable();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

Page 13
17MCA57 .NET LABORATORY
dt.Reset();
con.Open();
ds.Reset();
ds.Tables.Add(dt);
da = new SqlDataAdapter("select Subject_Name from subject", con);
da.Fill(dt);
dataGridView1.DataSource = dt.DefaultView;
con.Close();
cmd.Connection = con;
DataGridViewCheckBoxColumn cb = new DataGridViewCheckBoxColumn();
cb.Name = "cbc";
dataGridView1.Columns.Insert(0, cb);
loadlist();

}
public void loadlist()
{
con.Open();
cmd.CommandText = "select * from lecturer";
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
comboBox1.Items.Add(dr[1].ToString());
comboBox2.Items.Add(dr[1].ToString());
}
}
con.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs
e)
{

private void button1_Click_1(object sender, EventArgs e)


{
con.Open();
cmd.CommandText = "insert into subject values('" + textBox1.Text
+ "','" + textBox2.Text + "')";
cmd.ExecuteNonQuery();
cmd.Clone();
MessageBox.Show("Record inserted");
con.Close();
textBox1.Text = "";
textBox2.Text = "";
}

private void button2_Click(object sender, EventArgs e)


{
con.Open();
cmd.CommandText = "insert into lecturer values('" + textBox3.Text
+ "','" + textBox4.Text + "')";
cmd.ExecuteNonQuery();

Page 14
17MCA57 .NET LABORATORY
cmd.Clone();
MessageBox.Show("Record inserted");
con.Close();
textBox3.Text = "";
textBox4.Text = "";
}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs


e)
{
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();

con.Open();
ds1.Reset();
ds1.Tables.Add(dt1);
SqlDataAdapter da1 = new SqlDataAdapter("select * from ls where
Lecturer_Name='" + comboBox2.SelectedItem.ToString() + "'", con);
da1.Fill(dt1);
dataGridView2.DataSource = dt1.DefaultView;
con.Close();
}

private void button3_Click(object sender, EventArgs e)


{
int i = 0;

foreach(DataGridViewRow row in dataGridView1.Rows)


{
bool iss = Convert.ToBoolean(row.Cells["cbc"].Value);
if(iss)
{
cmd.CommandText = "insert into ls
values('"+comboBox1.SelectedItem.ToString()+"','"+row.Cells[1].Value+"')";

con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("inserted successfully");
}
}
i++;
}
}

3. Consider the database db_VSS (Vehicle Service Station) consisting of the following tables:
tbl_VehicleTypes(IdVehicleType: int, VehicleType: string, ServiceCharge: int)
tbl_ServiceDetails(IdService: int, VehicleNumber: string, ServiceDetails: string, IdVehicleType: int)
Develop a suitable window application using C#.NET having following options.
1. Enter new Service Details for the Selected Vehicle Type (In a Combo Box).
2. Update the Existing Service Charges to Database.

Page 15
17MCA57 .NET LABORATORY
3. Total Service Charges Collected for the Selected Vehicle (In a Combo box) with total amount displayed in a
text box.
NOTE: tbl_VehicleType is a static table containing the following Rows in it.
1 Two Wheeler 500
2 Four Wheeler 1000
3 Three Wheeler 700

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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=c:\users\gowtham\documents\visual studio
2010\Projects\WindowsFormsApplication3\WindowsFormsApplication3\Database1.mdf;Integrated
Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
SqlDataAdapter da;
DataSet ds = new DataSet();
DataTable dt = new DataTable();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)

Page 16
17MCA57 .NET LABORATORY
{
cmd.Connection = con;
loadlist();

}
public void loadlist()
{
con.Open();
cmd.CommandText = "select * from vehicle";
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
comboBox1.Items.Add(dr[1].ToString());

}
}
con.Close();
con.Open();
cmd.CommandText = "select * from service";
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
comboBox3.Items.Add(dr[1].ToString());
}
}
con.Close();

private void button1_Click(object sender, EventArgs e)


{
con.Open();
cmd.CommandText = "insert into service values('" + textBox1.Text + "','" +
textBox2.Text + "','" + textBox3.Text + "','" + comboBox1.SelectedItem.ToString() + "')";
cmd.ExecuteNonQuery();
cmd.Clone();
MessageBox.Show("Record inserted");
con.Close();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";

}
String a,tc;
private void Update_Click(object sender, EventArgs e)
{
con.Open();
cmd.CommandText = "select * from vehicle where vehicle_type='" +
textBox6.Text + "'";
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())

Page 17
17MCA57 .NET LABORATORY
{
a = dr[2].ToString();
}
}
con.Close();
textBox5.Text = Convert.ToString(Convert.ToInt64(textBox4.Text) +
Convert.ToInt64(a));

private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)


{
con.Open();
cmd.CommandText = "select * from service where vehicle_no='" +
comboBox3.SelectedItem.ToString() + "'";
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
textBox6.Text = dr[3].ToString();
}
}
con.Close();

}
}
4.Develop a web application using C#.NET and ASP.NET for the Complaint Management System. The
master page should contain the hyper links for Add Engineer, Complaint Registration, Complaint Allocation
1.Master page

<%@ Page Language="C#" MasterPageFile="~/MainMaster.Master"


AutoEventWireup="true" CodeBehind="welcomepage.aspx.cs"
Inherits="PostalSyatemManagement.welcomepage" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<h3> Welcome to the Postal System.......!Please look around the pages</h3>
</asp:Content>

Page 18
17MCA57 .NET LABORATORY

2.AREA details

<%@ Page Language="C#" MasterPageFile="~/MainMaster.Master"


AutoEventWireup="true" CodeBehind="areadetails.aspx.cs"
Inherits="PostalSyatemManagement.WebForm1" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Text="Area Details"></asp:Label>

<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:Label ID="Label2" runat="server" Text="Area Id: "></asp:Label>


<asp:TextBox ID="idArea" runat="server"></asp:TextBox>

Page 19
17MCA57 .NET LABORATORY
&nbsp;&nbsp;&nbsp;
<br />
&nbsp;<asp:Label ID="Label3" runat="server" Text="Area Name : "></asp:Label>
<asp:TextBox ID="AreaName" runat="server"></asp:TextBox>

&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;<asp:Button ID="btn_save" runat="server" Text="Save"
onclick="btn_save_Click" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="btn_clear" runat="server" Text="Clear" />
<br />
<br />
<asp:Label ID="successid" runat="server" Text="Successfully
inserted...!!!"
Visible="False"></asp:Label>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [tbl_AreaDetails]"></asp:SqlDataSource>
</asp:Content>

3.Postman details

<%@ Page Language="C#" MasterPageFile="~/MainMaster.Master"


AutoEventWireup="true" CodeBehind="postmandetails.aspx.cs"
Inherits="PostalSyatemManagement.WebForm2" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Text="Postman Details"></asp:Label>

<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:Label ID="Label2" runat="server" Text="Postman Id: "></asp:Label>

Page 20
17MCA57 .NET LABORATORY
&nbsp;<asp:TextBox ID="idPostman" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;
<br />
&nbsp;<asp:Label ID="Label3" runat="server" Text="Postman Name :
"></asp:Label>
&nbsp;<asp:TextBox ID="PostmanName" runat="server"></asp:TextBox>

&nbsp;&nbsp;&nbsp;
<br />
<asp:Label ID="Label4" runat="server" Text="Contact Number :
"></asp:Label>
<asp:TextBox ID="ContactNumber" runat="server"></asp:TextBox>

<br />
<asp:Label ID="Label5" runat="server" Text="Select Area : "></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:DropDownList ID="area" runat="server">
<asp:ListItem Value="1">First</asp:ListItem>
<asp:ListItem Value="2">Second</asp:ListItem>
<asp:ListItem Value="3">Third</asp:ListItem>
<asp:ListItem Value="4">Fourth</asp:ListItem>
</asp:DropDownList>

<br />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="btn_save" runat="server" Text="Save"
onclick="btn_save_Click" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="btn_clear" runat="server" Text="Clear" Visible="False" />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM
[tbl_PostmanDetails]"></asp:SqlDataSource>
<asp:Label ID="successid" runat="server" Text="Successfully
inserted...!!!"
Visible="False"></asp:Label>
</asp:Content>

4.Letter details

Page 21
17MCA57 .NET LABORATORY
<%@ Page Language="C#" MasterPageFile="~/MainMaster.Master"
AutoEventWireup="true" CodeBehind="letterdistribution.aspx.cs"
Inherits="PostalSyatemManagement.WebForm3" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Text="Area Details"></asp:Label>

<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:Label ID="Label2" runat="server" Text="Letter Id: "></asp:Label>


&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="idLetter" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;
<br />
&nbsp;<asp:Label ID="Label3" runat="server" Text="Letter Address :
"></asp:Label>
<asp:TextBox ID="letterAddress" runat="server"></asp:TextBox>

&nbsp;&nbsp;&nbsp;
<br />
<asp:Label ID="Label5" runat="server" Text="Select Area : "></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:DropDownList ID="area" runat="server">
<asp:ListItem Value="1">First</asp:ListItem>
<asp:ListItem Value="2">Second</asp:ListItem>
<asp:ListItem Value="3">Third</asp:ListItem>
<asp:ListItem Value="4">Fourth</asp:ListItem>
</asp:DropDownList>
<br />
<br />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="btn_save" runat="server" Text="Save"
onclick="btn_save_Click1" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="btn_clear" runat="server" Text="Clear"
onclick="btn_clear_Click" />
<br />
<asp:Label ID="Successid" runat="server" Text="Successfully
inserted...!!!"
Visible="False"></asp:Label>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [tbl_AreaLetters]"></asp:SqlDataSource>
<br />
</asp:Content>

5.Letter viewing

Page 22
17MCA57 .NET LABORATORY

<%@ Page Language="C#" MasterPageFile="~/MainMaster.Master"


AutoEventWireup="true" CodeBehind="vletter.aspx.cs"
Inherits="PostalSyatemManagement.WebForm4" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<div><h2>All Letter Addresses</h2></div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="idLetter" HeaderText="idLetter"
SortExpression="idLetter" />
<asp:BoundField DataField="LetterAddress"
HeaderText="LetterAddress"
SortExpression="LetterAddress" />
<asp:BoundField DataField="idArea" HeaderText="idArea"
SortExpression="idArea" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [tbl_AreaLetters]"></asp:SqlDataSource>
</asp:Content>

5.Develop the suitable content pages for the above created 4 hyper links with the following details:

1. Enter New Engineers belonging to the selected department (displayed in a combo box)
2. Register a new Complaint with a submit button.
3. View all registered complaints & allocate to the corresponding department (displayed in a combo box)
4. Display all the Complaints (In a Grid) to be handled by the selected Engineer (In a Combo box)

NOTE: Consider the table tbl_Departments as a static table containing some pre-entered departments,which are
displayed in all the remaining modules.

Steps:
New->Asp.net web forms project->Next->Give a name and Click on finish
Once project is opened Right Click on Project Name ->Select Add-> New Files -
>Select Web Form -> Give a name ->click New

Page 23
17MCA57 .NET LABORATORY
In this way create 3 files : complaintRegistration.aspx,
complaintAllocation.aspx , viewComplaint.aspx
Coding for Default.aspx :
<%@ Page Language="C#" Inherits="aspNet5.Default" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Complaint Management System</title>
script runat="server">
String ConnectionString="server="+"localhost"+";"+"Database="+"CMS"
+";"+"uid="+"root"+";"+"Password="+"India123"+";";
private void AddEngineer(Object sender,EventArgs e)
{
try
{

MySqlConnection conn=new
MySqlConnection(ConnectionString);
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText="insert into engineer
values("+eid.Text+",'"+ename.Text+"','"+contact.Text+"',"+depertment_id.Text+
")";
cmd.ExecuteNonQuery();
Label1.Text = "New Engineer Added Successfully";
conn.Close();
}catch(Exception )
{
Label1.Text = "Id Already existed";
}
}
</script>

</head>
<body>
<center>
<table cellpadding="10" border="0">
<tr>
<th width="300"><a href="Default.aspx">Add Engineer</a></th>
th width="300"><a href="complaintRegistration.aspx">Complaint
Registration</a></th>
th width="300"><a href="complaintAllocation.aspx">Complaint
Allocation</a></th>
th width="100"><a href="viewComplaint.aspx">View
Complaints</a></th>
</tr>
</table>
<form id="form1" runat="server">
<h1>Add a New Engineer</h1>
asp:Label ID="Label1" runat="server" Text=""></asp:Label><br />

Page 24
17MCA57 .NET LABORATORY
<label>Enter engineer ID</label><asp:TextBox id="eid" runat="server"
/><br/>
<label>Enter Name</label><asp:TextBox id="ename" runat="server"
/><br/>
<label>Enter Contact</label><asp:TextBox id="contact" runat="server"
/><br/>
<label>Select Department Name</label><asp:DropDownList
id="depertment_id" AutoPostBack="True" runat="server">
<asp:ListItem Selected="True" Value="1"> Road
</asp:ListItem>
asp:ListItem Value="2"> Bridge</asp:ListItem>
asp:ListItem Value="3"> Water</asp:ListItem>
asp:ListItem Value="4"> Power </asp:ListItem>
</asp:DropDownList><br/>
<asp:Button id="button1" runat="server" Text="AddEngineer"
onClick="AddEngineer" />
</form>
</center>
</body>
</html>

Coding for complaintRegistration.aspx:


<%@ Page Language="C#" Inherits="aspNet5.Default" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Complaint Management System</title>
script runat="server">
String ConnectionString="server="+"localhost"+";"+"Database="+"CMS"
+";"+"uid="+"root"+";"+"Password="+"India123"+";";
private void makeComplaint(Object sender,EventArgs e)
{
try
{

MySqlConnection conn=new MySqlConnection(ConnectionString);


conn.Open();
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText="insert into registered_complaint
values("+comp_id.Text+",'"+detail.Text+"')";
cmd.ExecuteNonQuery();
Label1.Text = "Complaint registered successfully";
conn.Close();

}catch(Exception )
{
Label1.Text = "Complaint id Already existed";
}
}
</script>
</head>
<body>

Page 25
17MCA57 .NET LABORATORY
<center>
<table cellpadding="10" border="0">
<tr>
<th width="300"><a href="Default.aspx">Add Engineer</a></th>
th width="300"><a href="complaintRegistration.aspx">Complaint
Registration</a></th>
th width="300"><a href="complaintAllocation.aspx">Complaint
Allocation</a></th>
th width="100"><a href="viewComplaint.aspx">View
Complaints</a></th>
</tr>
</table>
<form id="form1" runat="server">
<h1>Register New Complaint</h1>
asp:Label ID="Label1" runat="server" Text=""></asp:Label><br
/>
<table>
<tr><td><label>Complaint ID</label><asp:TextBox id="comp_id"
runat="server" /></td></tr>
tr><td><label>Enter description</label><asp:TextBox id="detail"
TextMode="multiline" Columns="50" Rows="5" runat="server" /></td></tr>
tr> <td><asp:Button id="button1" runat="server" Text="Submit"
onClick="makeComplaint" /></td></tr>
</table>
</form>
</center>
</body>
</html>

Coding for complaintAllocation.aspx :

<%@ Page Language="C#" Inherits="aspNet5.Default" %>


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>CMS</title>
script runat="server">
String ConnectionString="server="+"localhost"+";"+"Database="+"CMS"
+";"+"uid="+"root"+";"+"Password="+"India123"+";";
private void Page_Load(Object sender,EventArgs e)
{
MySqlConnection conn=new MySqlConnection(ConnectionString);
conn.Open();
String qry="select * from registered_complaint";
MySqlDataAdapter sd=new MySqlDataAdapter(qry,conn);
DataSet ds=new DataSet();
sd.Fill(ds,"output");
conn.Close();
Complaint.DataSource = ds.Tables["output"];
Complaint.DataBind();
}

Page 26
17MCA57 .NET LABORATORY
private void allocateComplaint(Object sender,EventArgs e)
{
try
{

MySqlConnection conn=new MySqlConnection(ConnectionString);


conn.Open();
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText="insert into department_complaint
values("+depart_id.Text+",'"+comp_id.Text+"')";
cmd.ExecuteNonQuery();
Label1.Text = "Complaint allocated successfully";
conn.Close();
}catch(Exception )
{
Label1.Text = "Complaint id Already existed";
}
}
</script>
</head>
<body>
<center>
<table cellpadding="10" border="0"><tr>
<th width="300"><a href="Default.aspx">Add Engineer</a></th>
th width="300"><a href="complaintRegistration.aspx">Complaint
Registration</a></th>
th width="300"><a href="complaintAllocation.aspx">Complaint
Allocation</a></th>
th width="100"><a href="viewComplaint.aspx">View
Complaints</a></th>
</tr>
</table>

<form id="form1" runat="server">


<h1>Allocate complaint </h1>
asp:Label ID="Label1" runat="server" Text=""></asp:Label><br
/>
<table>
<tr><th>Enter Complaint ID</th> <th>Select Department</th>
<th>Allocate</th></tr>
tr><td><asp:TextBox id="comp_id" runat="server" /></td>
td><asp:DropDownList id="depart_id" AutoPostBack="True"
runat="server">
<asp:ListItem Selected="True" Value="1"> Road
</asp:ListItem>
asp:ListItem Value="2"> Bridge</asp:ListItem>
asp:ListItem Value="3"> Water</asp:ListItem>
asp:ListItem Value="4"> Power </asp:ListItem>
</asp:DropDownList></td>
td><asp:Button id="button1" runat="server" Text="Allocate Complaint"
OnClick="allocateComplaint"/></td></tr>
</table>
</form>
asp:DataGrid runat="server" id="Complaint" />
</center>
</body>

Page 27
17MCA57 .NET LABORATORY
</html>

Coding for viewComplaint.aspx :

<%@ Page Language="C#" %>


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>viewComplaint</title>
script runat="server">
String ConnectionString="server="+"localhost"+";"+"Database="+"CMS"
+";"+"uid="+"root"+";"+"Password="+"India123"+";";
private void Page_Load(Object sender,EventArgs e)
{
MySqlConnection conn = new MySqlConnection(ConnectionString);
conn.Open();
String qry="select * from engineer";
MySqlDataAdapter sd=new MySqlDataAdapter(qry,conn);
DataTable dt = new DataTable();
sd.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();

}
private void viewComplaint(Object sender,EventArgs e)
{
try
{
MySqlConnection conn = new
MySqlConnection(ConnectionString);
conn.Open();
String qry = "select * from registered_complaint where
complaint_id in(select comp_id from department_complaint where department_id
in(select depart_id from engineer where name='" + DropDownList1.SelectedValue
+ "'))";
MySqlDataAdapter sd=new MySqlDataAdapter(qry,conn);
DataSet ds=new DataSet();
sd.Fill(ds,"output");
conn.Close();
GridView1.DataSource = ds.Tables["output"];
GridView1.DataBind();
Label1.Text = "record found";
}catch(Exception )
{
Label1.Text = "Data not found";
}

}
</script>

Page 28
17MCA57 .NET LABORATORY
</head>
<body>
<center>
<table cellpadding="10" border="0">
<tr>
<th width="300"><a href="Default.aspx">Add Engineer</a></th>
th width="300"><a href="complaintRegistration.aspx">Complaint
Registration</a></th>
th width="300"><a href="complaintAllocation.aspx">Complaint
Allocation</a></th>
th width="100"><a href="viewComplaint.aspx">View
Complaints</a></th>
</tr>
</table>
form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="View Complaint"
Style="height: 26px" OnClick="viewComplaint"/>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical"> </asp:GridView>
</form>
</center>
</body>
</html>

Table Structure :

Department Table : Insert data before

Page 29
17MCA57 .NET LABORATORY

Output :

Page 30
17MCA57 .NET LABORATORY

Page 31
17MCA57 .NET LABORATORY

Page 32

You might also like