C#.Net - Lab Manual
C#.Net - Lab Manual
T:+9180 28524466 / 77
LABORATORY MANUAL
Semester : V
Scheme : 2018
1 18MCA56 – C# .NET
Laboratory
PART - A
1.Write a Program in C# to demonstrate Command line arguments processing for the following.
a) To find the square root of a given number.
b) To find the sum & average of three numbers.
The Console Class provides access to the standard input, standard output, and standard error streams.
Standard input – is associated with the keyboard- anything that the user types on the keyboard can be
read from the standard input stream.
Console.Read Method – reads the next character from the keyboard. It returns the int value -1 if there is
no more input available. Otherwise it returns as int representing the character read.
Console.ReadLine Method - reads all characters up to the end of the input line. The input is returned as
a string of characters.
Standard output – is usually directed to the screen, as is the standard error stream.
Console.Write Method – writes text to the console without a carriage return
Console.WriteLine Method – writes a text string including a carriage return to the out console
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
namespace Squareroot_1A
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
2 18MCA56 – C# .NET
Laboratory
Console.WriteLine("No Arguments Passed");
}
else
{
Console.WriteLine("Following are the arguments");
double b = Math.Sqrt(a);
Console.WriteLine(b.ToString ()+ " , ");
}
}
Console.ReadLine();
}
}
}
Right click your project in Solution Explorer and select Properties from the menu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sumthree_1B
{
3 18MCA56 – C# .NET
Laboratory
class Program
{
static void Main(string[] args)
{
if (args.Length < 3)
{
Console.WriteLine("No arguments. ");
}
else
{
double a, b, c, tot, avg;
a = Convert.ToInt16(args[0]);
b = Convert.ToInt16(args[1]);
c = Convert.ToInt16(args[2]);
tot = a + b + c;
avg = tot / 3.0;
Console.WriteLine("Three given numbers :" + a.ToString() + ", " + b.ToString() + ", " +
c.ToString());
Console.WriteLine("Sum of the three given numbers :"+tot.ToString ());
Input : 4 7 22
4 18MCA56 – C# .NET
Laboratory
2. Write a Program in C# to demonstrate the following
a) Boxing and Unboxing b) Invalid Unboxing.
Boxing
It is defined as the process of explicitly converting a value type into a corresponding reference type by
storing the variable in a System.Object.
If, during the course of your application, you wish to represent this value type as a reference type, you would
“box” the value as follows:
// Box the value into an object reference.
object objShort = s;
Unboxing
It is the process of converting the value held in the object reference back into a corresponding value type on
the stack. The unboxing operation begins by verifying that the receiving data type is equivalent to the boxed
type, and if so, it copies the value back into a local stack-based variable.
The following unboxing operation works successfully, given that the underlying type of the objShort is indeed
a short.
namespace Prg_2a
{
class Program
{
static void box(object obj)
{
Console.WriteLine("Value : " + obj);
}
5 18MCA56 – C# .NET
Laboratory
double dd = (double)o; //Unboxing
Console.WriteLine("d= : " + dd);
Console.ReadLine();
}
}
}
b) Invalid Unboxing.
namespace Prg_2a
{
class Prg_2b
{
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);
}
Console.ReadLine();
}
}
}
6 18MCA56 – C# .NET
Laboratory
3. Write a program in C# to add Two complex numbers using Operator overloading .
class Prg3
{
class Complex
{
private int x, y;
public Complex() { }
public Complex(int i, int j)
{
x = i;
y = j;
}
public void ShowXY()
{
Console.WriteLine(Convert.ToString(x) + " " + Convert.ToString(y));
}
public static Complex operator -(Complex c)
{
Complex temp = new Complex();
temp.x = -c.x;
temp.y = -c.y;
return temp;
}
public static Complex operator +(Complex c1, Complex c2)
{
Complex temp = new Complex();
temp.x = c1.x + c2.x;
temp.y = c1.y + c2.y;
return temp;
}
}
static void Main(string[] args)
{
Complex c1 = new Complex(10, 20);
Complex c2 = new Complex(30, 40);
Complex c3, c4 = new Complex();
Console.Write("Complex Number1 :");
c1.ShowXY();
Console.Write ("Complex Number2 :");
c2.ShowXY();
c3 = -c1;
Console.Write("Changing the sign of Complex Number1 :");
c3.ShowXY();
7 18MCA56 – C# .NET
Laboratory
c4 = c1 + c2;
Console.Write("Addition of two complex Numbers 1 and 2:");
c4.ShowXY();
Console.ReadLine();
}
}
4. Write a Program in C# to find the sum of each row of given jagged array of 3 inner arrays.
A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different
dimensions and sizes. A jagged array is sometimes called an "array of arrays."
The following is a declaration of a single-dimensional array that has three elements, each of which is a
single-dimensional array of integers:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program4
{
class Program
{
static void Main(string[] args)
{
int[][] arr = new int[3][];
int arr0_length, arr1_length, arr2_length;
int i,j, sum;
8 18MCA56 – C# .NET
Laboratory
Console.WriteLine ("Enter the Element of First array : ");
for (i = 0; i < arr0_length; i++)
arr[0][i] = Convert.ToInt32(Console.ReadLine());
Output :
9 18MCA56 – C# .NET
Laboratory
5. Write a Program in C# to demonstrate Array Out of Bound Exception using Try, Catch and Finally blocks.
An exception is a problem that arises during the execution of a program. A C# exception is a response to
an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.
Exceptions provide a way to transfer control from one part of a program to another. C# exception handling
is built upon four keywords: try, catch, finally, and throw.
try: A try block identifies a block of code for which particular exceptions is activated. It is followed
by one or more catch blocks.
catch: A program catches an exception with an exception handler at the place in a program where
you want to handle the problem. The catch keyword indicates the catching of an exception.
finally: The finally block is used to execute a given set of statements, whether an exception is
thrown or not thrown. For example, if you open a file, it must be closed whether an exception is
raised or not.
throw: A program throws an exception when a problem shows up. This is done using a throw
keyword.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program_5
{
class Program
10 18MCA56 – C# .NET
Laboratory
{
static void Main(string[] args)
{
int[] a=new int[]{10,20,30,40,50};
Console.WriteLine("List of elements in the array : ");
try
{
for (int i=0; i<=5; i++)
Console.Write(a[i]+" ");
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine();
Console.WriteLine("Exception Caught:" + e.Message);
}
finally
{
Console.ReadLine();
}
}
}
}
11 18MCA56 – C# .NET
Laboratory
6.Write a Program to Demonstrate Use of Virtual and override key words in C# with a simple program
Overrriding method is basically run time polymorphism in C#. When a subclass contains a method with the
same name and signature as in the supper class then it is called as method overriding.
Virtual method is a method in a base class which the child class can reuse it or redefine and customize its
behavior to be appropriate to its functionality. The virtual keyword is used to modify a method, property,
indexer or event declaration, and allow it to be overridden in a derived class. For example, this method can
be overridden by any class that inherits it:
Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program6
{
public class Customer
{
public virtual void CustomerType()
{
Console.WriteLine("I am customer");
}
}
public class CorporateCustomer : Customer
{
public override void CustomerType()
{
Console.WriteLine("I am a Corporate Customer");
}
}
public class PersonalCustomer : Customer
{
public override void CustomerType()
{
Console.WriteLine("I am a personal customer");
}
}
class Program
{
static void Main(string[] args)
{
Customer[] c = new Customer[3];
c[0] = new Customer();
c[1] = new CorporateCustomer();
c[2] = new PersonalCustomer();
12 18MCA56 – C# .NET
Laboratory
}
}
}
7. Write a Program in C# to create and implement a Delegate for any two arithmetic operations
# delegates are similar to pointers to functions, in C or C++. A delegate is a reference type variable that
holds the reference to a method. The reference can be changed at runtime.
Delegates are especially used for implementing events and the call-back methods. All delegates are
implicitly derived from the System.Delegate class.
A delegate can refer to a method, which has the same signature as that of the delegate.
The preceding delegate can be used to reference any method that has a singlestring parameter and returns
an int type variable.
13 18MCA56 – C# .NET
Laboratory
static void Main(string[] args)
{
Operation doaddition = new Operation(Addtwonos);
Operation domultiplication = new Operation(Multwonos);
Console.Write("Enter Number 1 : ");
double n1 = Double.Parse(Console.ReadLine());
Console.Write("Enter Number 2 : ");
double n2 = Double.Parse(Console.ReadLine());
double sum = doaddition(n1, n2);
double mul = domultiplication(n1, n2);
Console.WriteLine("\n{0} + {1} = {2}\n", n1,n2, sum);
Console.WriteLine("\n{0} * {1} = {2}\n", n1, n2, mul);
Console.ReadLine();
}
}
14 18MCA56 – C# .NET
Laboratory
8. Write a Program in C# to demonstrate abstract class and abstract methods in C#.
The abstract keyword enables you to create classes and class members that are incomplete and must be
implemented in a derived class.
An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common definition
of a base class that multiple derived classes can share. For example, a class library may define an abstract
class that is used as a parameter to many of its functions, and require programmers using that library to
provide their own implementation of the class by creating a derived class.
Abstract classes may also define abstract methods. This is accomplished by adding the
keyword abstract before the return type of the method. For example:
Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program8
{
public abstract class Vehicle
{
public string Name;
public int Wheels;
public double Amount;
public abstract void Calculate();
}
public class Motorcycle : Vehicle
{
public Motorcycle()
{
this.Wheels = 2;
}
public Motorcycle(string s)
{
this.Wheels = 2;
this.Name = s;
}
public override void Calculate()
{
this.Amount = 100000 + (500 * this.Wheels);
Console.WriteLine("This motor cycle name is " + this.Name + " and its price is " + this.Amount);
}
}
public class Car : Vehicle
{
private string EngineType;
public Car()
{
15 18MCA56 – C# .NET
Laboratory
this.Wheels = 4;
}
public Car(string s, string t)
{
this.Wheels = 4;
this.Name = s;
this.EngineType = t;
}
public override void Calculate()
{
this.Amount = 400000 + (500 * this.Wheels) + 8000;
Console.WriteLine("This car name is " + this.Name + " has engine type " + this.EngineType + " and
price " + this.Amount);
}
}
class Program
{
static void Main(string[] args)
{
Vehicle v;
Motorcycle m = new Motorcycle("Pulsar");
Car c = new Car("Jazz", "Tata");
v = m;
v.Calculate();
v = c;
v.Calculate();
Console.ReadLine();
}
}
}
16 18MCA56 – C# .NET
Laboratory
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#.
Properties enable a class to expose a public way of getting and setting values, while hiding implementation
or verification code. The get property accessor is used to return the property value, and a set accessor is
used to assign a new value. These accessors can have different access levels. The value keyword is used
to define the value being assigned by the set indexer.
class Student
{
private string fullName;
private int ageyears;
class Prg9
{
static void Main(string[] args)
{
Student e = new Student();
e.Name = "Saran";
e.Age = 25;
Console.WriteLine("Name ={0}", e.Name);
Console.WriteLine("Age = {0}", e.Age);
Console.ReadLine();
}
}
17 18MCA56 – C# .NET
Laboratory
18 18MCA56 – C# .NET
Laboratory
10. Write a Program in C# Demonstrate arrays of interface types (for runtime polymorphism).
An interface looks like a class, but has no implementation. The only thing it contains are declarations
of events, indexers, methods and/or properties. The reason interfaces only provide declarations is because
they are inherited by classes and structs, which must provide an implementation for each interface .
interface IMyInterface
{
void MethodToImplement();
}
The above code defines an interface named IMyInterface. A common naming convention is to prefix all
interface names with a capital “I”. This interface has a single method named MethodToImplement().
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program10
{
public interface IShape
{
void Calculate();
void Display();
}
public class Rectangle : IShape
{
private double Area;
private double Length;
private double Breadth;
public Rectangle()
{
this.Length = 0;
this.Breadth = 0;
}
public Rectangle(double l, double b)
{
this.Length = l;
this.Breadth = b;
}
public void Calculate()
{
this.Area = this.Length * this.Breadth;
}
public void Display()
{
Console.WriteLine("Area of Rectangle is : " + this.Area);
}
}
public class Square : IShape
{
private double Area;
private double Side;
public Square()
{
19 18MCA56 – C# .NET
Laboratory
this.Side = 0;
}
public Square(double s)
{
this.Side = s;
}
public void Calculate()
{
this.Area = this.Side * this.Side;
}
public void Display()
{
Console.WriteLine("Area of Square is : " + this.Area);
}
}
public class Circle : IShape
{
private double Area;
private double Radius;
public Circle()
{
this.Radius = 0;
}
public Circle(double s)
{
this.Radius = s;
}
public void Calculate()
{
this.Area = 3.1416 * this.Radius * this.Radius;
}
public void Display()
{
Console.WriteLine("Area of Circle is : " + this.Area);
}
}
class Program
{
static void Main(string[] args)
{
IShape[] s = { new Rectangle(10, 20), new Square(30), new Circle(40) };
for (int i = 0; i < s.Length; i++)
{
s[i].Calculate();
s[i].Display();
}
Console.ReadLine();
}
}
}
20 18MCA56 – C# .NET
Laboratory
21 18MCA56 – C# .NET
Laboratory
PART - B
1. Consider the Database db_EMS (Employee Management System) consisting of the following tables :
Form1.cs
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
1|Page
22 18MCA56 – C# .NET
Laboratory
}
Add_Employee.cs
using System.Data;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Add_Employee : Form
{
private OleDbConnection conn;
private OleDbCommand oleDbCmd = new OleDbCommand();
private String connStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Helen\Documents\db_EMS.accdb";
public Add_Employee()
{
conn = new OleDbConnection(connStr);
InitializeComponent();
3|Page
oleDbCmd.CommandText = str;
int temp = oleDbCmd.ExecuteNonQuery();
if (temp > 0)
{
MessageBox.Show("New Employee detail is Added");
}
else
{
MessageBox.Show("Record Fail to Added");
}
conn.Close();
}
}
}
Display_PL.cs
using System.Data;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Display_PL : Form
{
private OleDbConnection conn;
private OleDbCommand oleDbCmd = new OleDbCommand();
private String connStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Helen\Documents\db_EMS.accdb";
public Display_PL()
{
conn = new OleDbConnection(connStr); InitializeComponent();
4|Page
Console.WriteLine(e.ToString()); Console.ReadLine();
return;
}
finally
{
conn.Close();
}
}
conn.Close();
}
}
}
Display_Engg.cs
using System.Data;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Display_Engg : Form
{
private OleDbConnection conn;
private OleDbCommand oleDbCmd = new OleDbCommand();
private String connStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Helen\Documents\db_EMS.accdb";
public Display_Engg()
{
conn = new OleDbConnection(connStr); InitializeComponent();
}
conn.Close();
}
}
Display_Emp.cs
using System.Data;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Display_Emp : Form
{
private OleDbConnection conn;
private OleDbCommand oleDbCmd = new OleDbCommand();
private String connStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Helen\Documents\db_EMS.accdb";
6|Page
.Net Laboratory – 16MCA 57 Part – B
public Display_Emp()
{
conn = new OleDbConnection(connStr);
InitializeComponent();
}
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(query, conn); DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
conn.Close();
}
}
}
Form1.cs
7|Page
Add_Employee.cs : Employee details with designation & Reporting Manager
Display_PL.cs
Display_Emp.cs
Display_Engg.cs
9|Page
2. Consider the Database db_LSA (Lecturer Subject Allocation) consisting of the following tables:
using System;
using System.Data;
using System.Data.OleDb;
namespace Lecturer_Subject_Allocation
{
public partial class Form1 : Form
{
private OleDbConnection conn;
private OleDbCommand oleDbCmd = new OleDbCommand();
private String connStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Helen\Documents\db_LSA.accdb";
public Form1()
{
conn = new OleDbConnection(connStr); InitializeComponent();
}
int totsub = 0;
for (int i=0; i<=dataGridView1.RowCount-1;i++)
{
if
(Convert.ToBoolean(dataGridView1.Rows[i].Cells["Column1"].Value)==true)
{
subid = Convert.ToInt16(dataGridView1.Rows[i].Cells[1].Value);
subcode = dataGridView1.Rows[i].Cells[2].Value.ToString();
conn.Open();
int lecid = Convert.ToInt16(comboBox1.SelectedValue);
oleDbCmd.Connection = conn;
String str = "insert into tbl_LecturerSubjects(IdSubject,SubjectCode, IdLecturer) values (" + subid +",'"+ subcode
+ "'," + lecid + ");";
oleDbCmd.CommandText = str;
int temp = oleDbCmd.ExecuteNonQuery();
if (temp > 0)
{
totsub = totsub + 1;
}
else
{
MessageBox.Show("Record Fail to Add");
}
conn.Close();
}
}
MessageBox.Show(totsub.ToString() + "subjects has been allocated");
}
conn.Close();
}
this.Close();
conn.Close();
}
}
}
namespace Vehicle_Service_Station
{
public partial class Form1 : Form
{
upserv.Show();
}
}
}
Add_Service
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Vehicle_Service_Station
{
public partial class Add_Service : Form
{
private OleDbConnection conn;
private OleDbCommand oleDbCmd = new OleDbCommand();
private String connStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Helen\Documents\db_VSS.accdb";
public Add_Service()
{
conn = new OleDbConnection(connStr); InitializeComponent();
}
}
catch (OleDbException e)
{
Console.WriteLine(e.ToString()); Console.ReadLine();
return;
}
finally
{
conn.Close();
}
}
String str = "insert into tbl_ServiceDetails( VehicleNumber, ServiceDetails, IdVehicleType) values ('" + textBox1.Text + "','" +
textBox2.Text + "'," + vech_id + ");";
oleDbCmd.CommandText = str;
int temp = oleDbCmd.ExecuteNonQuery();
if (temp > 0)
{
MessageBox.Show("New Service detail is Added");
}
else
{
MessageBox.Show("Record Fail to Added");
}
conn.Close();
}
}
}
Update_Serv
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb;
namespace Vehicle_Service_Station
{
public partial class Update_Serv : Form
{
private OleDbConnection conn;
private OleDbCommand oleDbCmd = new OleDbCommand();
public Update_Serv()
{
conn = new OleDbConnection(connStr); InitializeComponent();
}
load_Vechicletype();
}
catch (OleDbException e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
return;
}
finally
{
conn.Close();
}
}
int n = Convert.ToInt32((oleDbCmd.ExecuteScalar()));
textBox1.Text = Convert.ToString(n);
conn.Close();
int newcharge=Convert.ToInt32(textBox1.Text);
// String str = "update tbl_ServiceDetails set ( VehicleNumber, ServiceDetails, IdVehicleType) values ('" +
textBox1.Text + "','" + textBox2.Text + "',"
+ vech_id + ");";
String str ="update tbl_VehicleTypes SET ServiceCharges = "+newcharge+" where
IdVehicleType="+vech_id;
oleDbCmd.CommandText = str;
int temp = oleDbCmd.ExecuteNonQuery();
if (temp > 0)
{
}
}
else
{
MessageBox.Show("Re
cord updated");
MessageBox.Show("Re
cord Fail to Update");
conn.Close();
Calc_total
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb;
namespace Vehicle_Service_Station
{
public partial class Calc_total : Form
{
private OleDbConnection conn;
private OleDbCommand oleDbCmd = new OleDbCommand();
public Calc_total()
{
conn = new OleDbConnection(connStr);
InitializeComponent();
}
int n = Convert.ToInt32((oleDbCmd.ExecuteScalar()));
textBox1.Text = Convert.ToString(n);
conn.Close();
}
}
}
Output
4. Develop a web application using C#.NET and ASP.NET for the Postal System Management. The master
page should contain the hyper links for adding Area Details, Postman details, Letter distributions and
View Letters.
Consider the database db_PSM (Postal System Management) consisting of the following tables:
tbl_AreaDetails(IdArea: int, AreaName: string)
tbl_PostmanDetails(IdPostman: int, PostmanName: string, ContactNumber: string, IdArea: int)
tbl_AreaLetters(IdLetter: int, LetterAddress: string, IdArea: int)
Develop the suitable content pages for the above created 4 hyper links with the following details:
1. Enter New Area Details
2. Enter New Postman Details with the Area he/she is in-charge of (display Area in a Combo box)
3. Enter all the Letters distributed to the selected Area (display Area in a Combo box)
4. Display all the Letter addresses (In a Grid) to be distributed by the selected Postman (In a Combo box)
area_details
using System;
using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
}
}
}
PostMan_details
using System;
using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
load_areaname();
}
String query="select IdArea,AreaName from tbl_AreaDetails"; OleDbCommand cmd = new OleDbCommand(query, con);
DropDownList1.DataSource=cmd.ExecuteReader();
string query = "insert into tbl_PostmanDetails (PostmanName,ContactNumber,IdArea) values ('" + TextBox1.Text + "','" +
TextBox2.Text + "',"+ DropDownList1.SelectedValue+")";
OleDbCommand cmd = new OleDbCommand(query, con);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script language='javascript'>alert('Inserted
Succesfully')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('Insertion
Failed')</script>");
}
}
}
Distrib_letters
using System;
using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
String query = "select IdArea,AreaName from tbl_AreaDetails"; OleDbCommand cmd = new OleDbCommand(query, con);
DropDownList1.DataSource = cmd.ExecuteReader();
string query = "insert into tbl_AreaLetters (LetterAddress,IdArea) values ('" + TextBox2.Text + "'," +
DropDownList1.SelectedValue + ")";
OleDbCommand cmd = new OleDbCommand(query, con);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script language='javascript'>alert('Inserted
Succesfully')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('Insertion
Failed')</script>");
}
}
}
View_letter
using System;
using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
String query = "select IdArea,PostmanName from tbl_PostmanDetails"; OleDbCommand cmd = new OleDbCommand(query,
con);
DropDownList1.DataSource = cmd.ExecuteReader();
con.Open();
string query = "select IdLetter, LetterAddress from tbl_AreaLetters where
IdArea=" + DropDownList1.SelectedValue;
OleDbCommand cmd = new OleDbCommand(query, con); OleDbDataAdapter da = new OleDbDataAdapter(cmd);
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
5. 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 and View Complaints.
Consider the database db_CMS (Complaint Management System) consisting of the following tables:
tbl_Departments(IdDepartment: int, DepartmentName: string)
tbl_Engineers(IdEngineer: int, EngineerName: string, ContactNumber: string, IdDepartment: int)
tbl_RegisteredComplaints(IdComplaint: int, ComplaintDescription: string)
tbl_DepartmentComplaints(IdDepartment: int, IdComplaint: int)
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
Add_Engg
using System;
using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
}
}
DropDownList1.Items.Insert(0, new ListItem("--Select Customer--", "0"));
}
string query = "insert into tbl_Engineers (EngineerName,ContactNumber,IdDepartment) values ('" + TextBox1.Text + "','" +
TextBox2.Text + "'," + DropDownList1.SelectedValue + ")";
OleDbCommand cmd = new OleDbCommand(query, con);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script language='javascript'>alert('Inserted
Succesfully')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('Insertion
Failed')</script>");
}
}
}
Reg_Compliant.cs
using System;
using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(connStr);
con.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script language='javascript'>alert('Inserted
Succesfully')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('Insertion
Failed')</script>");
}
}
}
Complaint_Allocation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
DropDownList2.DataSource = cmd.ExecuteReader();
DropDownList1.DataSource = cmd.ExecuteReader();
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(connStr);
con.Open();
Response.Write("<script language='javascript'>alert('Insertion
Failed')</script>");
}
}
}
View_Complaint
using System;
using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
DropDownList1.DataSource = cmd.ExecuteReader();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(connStr);
try
{
con.Open();
string query = "select ComplaintDescription from tbl_RegisteredComplaints
where IdComplaint IN (Select IdComplaint from tbl_DepartmentComplaints where IdDepartment
="+ DropDownList1.SelectedValue+")";
OleDbCommand cmd = new OleDbCommand(query, con);