Vous êtes sur la page 1sur 234

PROJECT REPORT

ON
ATTENDANCE ANALYSIS SYSTEM
IN PARTIAL FULFILLMENT OF THE REQUIREMENT
FOR THE AWARD OF

THE DEGREE IN BACHELOR OF ENGINEERING

(INFORMATION TECHNOLOGY)

SESSION: 2007-2008
(.NET TECHNOLOGY BASED MAJOR PROJECT)

SUBMITTED BY:

Vartika Paul (4 IT 55)


Sonali Khurana(4 IT 63)
Renu Yadav (4 IT 35)

LINGAYA’S INSTITUTE
OF
MANAGEMENT & TECHNOLOGY
FARIDABAD (HARYANA)
MAHARISHI DAYANAND UNIVERSITY
ROHTAK
ACKNOWLEDGEMENT

Before going to actual subject we would like to express our sincere


thanks and gratitude to all those who have helped us in making project.
We have the privilege to express our profound sense of gratitude to
Dr. Sunil Kumar and The Management for bestowing the valuable
support.

We want to give best regards to Prof. Tapas Kumar who gave us


fruitful opportunity to expose our knowledge by doing this project.

Finally we heartily thanks to all our family members without whose


cooperation the work would not have been completed.

Team Members:

 VARTIKA PAUL

 SONALI KHURANA

 RENU YADAV
1. Abstract

2. Brief description about project

3. System specifications

4. Introduction about Dot Net

5. Scope and Objective

6. Output and Coding

7. References
Brief Description About Project

“Attendance Analysis System” is developed, keeping in mind the


requirements about day-to-day handling of attendance of the
students by the faculties in the engineering colleges. By using
Attendance analysis system, a lecturer can keep track of
attendance of every student, analyze it and finally build a
Microsoft Word based report.

Since this project is build for an engineering college, first let us


explain you the academic structure in an engineering college. An
engineering college is made up of different departments like
Information Technology, Computers, Electronics,
Instrumentation, and Mechanical and so on. These departments
consists of different classes like FE (First Yr. Engg.), SE (Second
Yr. Engg.), TE (Third Yr. Engg.) & BE (the Final Year). Each year is
made up of two semesters. Each semester has some set of
subjects & these subjects are taught by the lecturers to the
students. A student is always unique to a department. A lecturer
can held any number of subjects under any department.

Some features of the project:

The project is designed on the Visual Studio 2005. Its


front-end uses a Visual C# application interfaced with a back-end
as Microsoft Access, to store the data collected by the
application. Few key features of the project are as follows:

Easy to understand & operate: The application has a convenient


user interface complied using latest Visual C# complier under
Microsoft .NET Framework for making its usage more easy to
understand and convenient to operate.

Build Word Document based report: This project helps a user is


to create a Word document of the attendance sheet that is
retrieved from the application. The application also uses some of
the resources under the Microsoft Office 2003, like Word &
Access.

How to use the application: The use of Attendance Analysis


System is best explained, menu wise, in a step by step
representation:

Step 1. Create Department.

step 2. Create Class per Department.

Step 3. Add Lecturer in Department.

Step 4. Add Subject in Class.

Step 5. Add Student in Class.

Step 6. Register Lecturer

Step 7. Register Students

Step 8. Add attendance of Students for registered subject.

Step 9. Display and build Word based attendance analysis report


SYSTEM SPECIFICATIONS

HARDWARE REQUIREMENTS

 SYSTEM
 MINIMUM 256MB RAM

SOFTWARE REQUIREMENTS

 MICROSOFT VISUAL STUDIO 2OO5 (C# DOT NET)


 MS OFFICE 2003 (MS ACCESS)
INTRODUCTION

ABOUT DOT NET

When Microsoft formally introduced its .NET strategy in mid-


2000, analysts were confused about how the company would pull
off such a massive platform shift. Two years later, they're still
wondering. But .NET isn't vaporware, and it's not a pipe dream.
In fact, .NET is happening today.

It's a dessert topping, it's a floor cleaner--it's a dessert topping


and a floor cleaner! Actually, .NET is many things, but primarily
it's a marketing term for a set of products and technologies that
Microsoft is creating to move personal and enterprise computing
beyond the PC desktop and into a distributed Internet-based
environment. So .NET--which was originally called Next
Generation Windows Services (NGWS)--is also a platform, one
that Microsoft sees as the successor to Windows. The .NET
platform is based on Web services which are, in turn, defined by
a language called XML.

XML--the extensible Markup Language--is a self-descriptive,


data definition language. It's similar to HTML, the language of
the Web, but it's far more powerful because it's not limited to a
static list of language constructs ("tags") that the language's
authors supply. Instead, XML is extensible and dynamic:
Programmers can define new types of data using XML and then
describe that data so that others will know how to use it.
Web services are server-side applications that expose their
services as programmable units that other applications (and Web
services) can access over the Internet.

It's possible the .NET platform could be ported to other


operating systems, such as Linux, FreeBSD, the Macintosh, or
whatever, and indeed, some work is being done now in this area.
However, .NET very much requires Windows today, on both the
server and the client. One might say that .NET and Windows have
a symbiotic relationship.

A company called Ximian is porting the standards-based parts


of .NET to Linux as you read this, and the work is amazingly far
along. Code-named Mono, this project seeks to bring the C#
programming language, the Common Language Runtime (CLR, see
below), and other .NET features to Linux.

On a related note, Microsoft has contracted Corel (makers of


CorelDraw and Word Perfect) to port .NET to FreeBSD at some
undetermined date in the future. This project has not yet
started.

You can run .NET client applications and services on Windows 98,
98 SE, Millennium Edition (Me), NT 4.0, 2000, or XP. Beginning in
late 2002, you will be able to run .NET applications and services
on Windows CE .NET products, such as the Pocket PC and
Microsoft Smart Phone, as well. On the server; you can use
Windows NT 4.0, 2000, or .NET Server.

Windows XP has got features of .Net but not many. Because


Windows XP was designed and built before the .NET Framework
was complete, it only includes bare-bones .NET functionality. The
primary conduit for .NET in XP is Windows Messenger, which is
used to expose .NET alert and rendezvous services. XP also
includes integration with the .NET Passport service, so that you
can optionally auto-logon to Passport when you logon to Windows.

.NET is comprised of several related technologies, including:

.NET Framework - A runtime environment and set of standard


services which .NET capable applications and services can utilize.
Implemented as a code library, the .NET Framework includes the
Common Language Runtime (CLR), the .NET run-time environment;
ASP .NET, a Web applications platform; and ADO .NET, for data
store access. Microsoft will ship a version of the .NET
Framework--dubbed the .NET Compact Framework--for Pocket
PCs, Microsoft Smart Phones, and other similar devices in late
2002.

.NET My Services - A set of free, consumer-oriented services


that will expand on .NET Passport's authentication services
(available today) to offer Web server-based storage of personal
information such as name and address, calendar, address book,
and credit card information. Microsoft expects to ship .NET My
Services (previously code-named Hailstorm) for consumers by the
end of 2002. A business oriented version of .NET My Services is
also in the works.

.NET Enterprise Servers - A set of expensive Microsoft server


software that runs on Windows servers, including Application
Server, BizTalk Server, Exchange Server, Host Integration
Server, Internet Security and Acceleration Server, SQL Server,
and many others. Microsoft is currently shipping many such
server products, but they are all based on Windows DNA
currently, not .NET. Future server products--beginning with
Windows .NET Server, due in late 2002--will actually be based on
.NET technologies for the first time.

Visual Studio .NET - Microsoft's .NET development environment,


with support for languages such as Visual Basic .NET, Visual C+
+ .NET, and Visual C# .NET, which all target the .NET
Framework. Other vendors can add other language capabilities to
Visual Studio .NET, and the suite can be used to target a wide
range of applications and services, including .NET Web services,
Windows applications, and Web applications. Note that Visual
Studio .NET is not required to create .NET applications and
services: Developers can download the .NET Framework for free;
this download includes compilers for Visual Basic .NET, Visual C++
.NET and Visual C# .NET.
Scope and Objective

Scope

We have made Attendance Analysis System by using this a


lecturer can keep track of the attendance of the students.

Objective

To save the time and effort in managing the attendance records,


calculating the percentage of attendance for a particular student
for each particular subject.
OUTPUT AND CODING

FORM-1

Display Menu strip (which include Department menu, class menu,


Lecturer menu, Subject menu, Student Menu, Registration Menu,
attendance Menu and About Menu).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Attendance
{
// Form1: Display Menustrip (which include Department menu, class
menu, Lecturer menu, Subject menu, Student Menu, Registration Menu,
attendance Menu and About Menu)

public partial class Form1 : Form


{
public Form1()
{
InitializeComponent();
}

//Department Menu
private void newDepartmentToolStripMenuItem_Click(object
sender, EventArgs e)
{
//Display New Department Name form
Form2 a = new Form2();
a.Show();
}

private void modifyDepartmentNameToolStripMenuItem_Click(object


sender, EventArgs e)
{
//Display Modify Department Name form
Form3 a = new Form3();
a.Show();
}

private void deleteDepartmentToolStripMenuItem_Click(object


sender, EventArgs e)
{
//Delete Department Name form
Form4 a = new Form4();
a.Show();
}

private void
displayDepartmentListToolStripMenuItem_Click(object sender, EventArgs
e)
{
//Display Department Names form
Form5 a = new Form5();
a.Show();
}

//Class Menu
private void newClassNameToolStripMenuItem_Click(object sender,
EventArgs e)
{
//Display New Class Name form
Form6 a = new Form6();
a.Show();
}

private void modifyClassNameToolStripMenuItem_Click(object


sender, EventArgs e)
{
//Display Modify Class Name form
Form7 a = new Form7();
a.Show();
}

private void deleteClassNameToolStripMenuItem_Click(object


sender, EventArgs e)
{
//Display Delete Class Name form
Form8 a = new Form8();
a.Show();
}

private void displayClassNameListToolStripMenuItem_Click(object


sender, EventArgs e)
{
//Display Class Names form
Form9 a = new Form9();
a.Show();
}

//Lecturer Menu
private void
addNewLecturerInDepartmentToolStripMenuItem_Click(object sender,
EventArgs e)
{
//Display New Lecturer Name form
Form10 a = new Form10();
a.Show();
}

private void modifyLecturerNameToolStripMenuItem_Click(object


sender, EventArgs e)
{
//Display Modify Lecturer Name form
Form11 a = new Form11();
a.Show();
}
private void deleteLecturerNameToolStripMenuItem_Click(object
sender, EventArgs e)
{
//Display Delete Lecturer Name form
Form12 a = new Form12();
a.Show();
}

private void
displayListOfLecturerInDepartmentToolStripMenuItem_Click(object sender,
EventArgs e)
{
//Display Lecturer Names form
Form13 a = new Form13();
a.Show();
}

//Subject Menu
private void addNewStudentInClassToolStripMenuItem_Click(object
sender, EventArgs e)
{
//Display New Subject Name form
Form14 a = new Form14();
a.Show();
}

private void modifyStudentNameToolStripMenuItem_Click(object


sender, EventArgs e)
{
//Display Modify Subject Name form
Form15 a = new Form15();
a.Show();
}

private void
deleteStudentNameFromClassToolStripMenuItem_Click(object sender,
EventArgs e)
{
//Display Delete Subject Name form
Form16 a = new Form16();
a.Show();
}

private void displayLToolStripMenuItem_Click(object sender,


EventArgs e)
{
//Display "Display Subject Names" form
Form17 a = new Form17();
a.Show();
}

//Student Menu
private void
addNewStudentInClassToolStripMenuItem1_Click(object sender, EventArgs
e)
{
//Display "New Student Name" form
Form18 a = new Form18();
a.Show();
}

private void deleteToolStripMenuItem_Click(object sender,


EventArgs e)
{
//Display "Modify Student Name" form
Form19 a = new Form19();
a.Show();
}

private void modifyStudentNameToolStripMenuItem1_Click(object


sender, EventArgs e)
{
//Display "Delete Student Name" form
Form20 a = new Form20();
a.Show();
}

private void
displayListOfStudentInClassToolStripMenuItem_Click(object sender,
EventArgs e)
{
//Display "Display Student Names" form
Form21 a = new Form21();
a.Show();
}
//Registration Menu
//Lecturer Registration Menu
private void
registerLecturerNameForASubjectToolStripMenuItem_Click(object sender,
EventArgs e)
{
//Display "Register Lecturer Name for a Subject" form
Form22 a = new Form22();
a.Show();
}

private void
deRegisterLecturerNameForASubjectToolStripMenuItem_Click(object sender,
EventArgs e)
{
//Display "DeRegister Lecturer Name for a Subject" form
Form23 a = new Form23();
a.Show();
}

private void
displayListOfRegisteredSubjectInSemesterToolStripMenuItem_Click(object
sender, EventArgs e)
{
//Display "Display List of Registered Subject in Semester"
form
Form24 a = new Form24();
a.Show();
}
//Studentt Registration Menu
private void registerStudentsNameToolStripMenuItem_Click(object
sender, EventArgs e)
{
//Display "Register Student Name for a subject" form
Form25 a = new Form25();
a.Show();
}

private void deRegisterStudentToolStripMenuItem_Click(object


sender, EventArgs e)
{
//Display "DeRegister Student Name for a subject" form
Form26 a = new Form26();
a.Show();
}

private void
displayListOfStudentRegisterForASubjectToolStripMenuItem_Click(object
sender, EventArgs e)
{
//Display "Display List of student register for a subject"
form
Form27 a = new Form27();
a.Show();
}

//Attendance Menu
private void addAttendanceToolStripMenuItem_Click(object
sender, EventArgs e)
{
//Display "Add Attendance (Subject wise)" form
Form28 a = new Form28();
a.Show();
}

private void printSavedAttendanceToolStripMenuItem_Click(object


sender, EventArgs e)
{
//Display "Build Attendnace Document (subject wise)" form
Form29 a = new Form29();
a.Show();
}

//About Menu
private void creditsToolStripMenuItem_Click(object sender,
EventArgs e)
{
//Show Message
MessageBox.Show("\nOur Special Thanks To Mr. Vijay Mukhi
Sir & entire VMCI staff \n\nAttendance Analysis Software is developed
by \nDhiraj Vanmali, \nAniket Vanmali, \nRohan Shringarpure, \nSainath
Patil"," Credits");
}

private void Form1_Load(object sender, EventArgs e)


{

private void attendanceToolStripMenuItem_Click(object sender,


EventArgs e)
{

}
FORM-2

STEP1- CREATE DEPARTMENT(DEPARTMENT MENU).

Display "New Department Name" form.

Creating a department is the first and the crucial step in the


Attendance Analysis System, so to create a new department first
click on “Department” menu and then click "New Department
Name" as shown in Figure.
On clicking, the "New Department Name" form is displayed on
the screen where you have to type the names of each department
on a new line. Once you typed in the required department names
click "Add". As shown in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form2: Display "New Departemnt Name" form

public partial class Form2 : Form


{
OleDbConnection DBCon1; // Database Connection
int IDept_id; // Department ID counter (Integer)

public Form2()
{
InitializeComponent();

//Intialise New Database Connection


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open Database Connection


DBCon1.Open();
}

~Form2()
{
//Close DataBase Connection
DBCon1.Close();
}

//This method will provide Max DepartmentId to add new


Department
private void Form2_Load(object sender, EventArgs e)
{
//Get Next Department ID
OleDbCommand DBcom1; // Database Command1
//Set Command to select Maximum Department ID
DBcom1 = new OleDbCommand("SELECT MAX(DEPT_ID) AS Expr1
FROM DEPARTMENT", DBCon1);
// Read From Database
try
{
IDept_id = (int)DBcom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
IDept_id = 0;
}
catch (System.InvalidCastException)
{
IDept_id = 0;
}

// Increment Department ID counter for next Department


IDept_id++;

//Dispose Database Command 1


DBcom1.Dispose();

//This Method will Add New Department in Database


private void button1_Click(object sender, EventArgs e)
{
int IRTBLines = 0; // Counter Represent Lines from
RichTextBox
//Read Lines from RichTextBox
for (IRTBLines = 0; IRTBLines < richTextBox1.Lines.Length;
IRTBLines++)
{
//If IRTBLine is not Null Then
if (string.Compare(richTextBox1.Lines[IRTBLines], "")
!= 0)
{
//Data Base Command 2
OleDbCommand DBcom2 = new OleDbCommand("select *
from department where dept_name ='" + richTextBox1.Lines[IRTBLines] +
"'", DBCon1);

//Database Reader 2
OleDbDataReader DBRead2;

//Read From Database


DBRead2 = DBcom2.ExecuteReader();

// Check if Department Name is Exist


if (DBRead2.HasRows)
{
//Department Name is Already Exist
MessageBox.Show("Department Name =" +
richTextBox1.Lines[IRTBLines] + " is skiped because it is already
exist");
//Dispose Database command 2 and reader 2
DBRead2.Dispose();
DBcom2.Dispose();
}
else
{
//Department Name is Not Already Exist
//Database Command3 String
string SCom1 = "insert into department values("
+ IDept_id + ",'" + richTextBox1.Lines[IRTBLines].ToString() + "')";
//Dispose Databse command 2 and reader 2
DBRead2.Dispose();
DBcom2.Dispose();

//Database Command 3
OleDbCommand DBcom3 = new OleDbCommand(SCom1,
DBCon1);

//Execute Database Command 3.


DBcom3.ExecuteNonQuery();

//Dispose Database Command 3


DBcom3.Dispose();

//Increment Department ID Counter


IDept_id++;
}

}
}

//Clear RichTextBox1 Content


richTextBox1.ResetText();

}
}

}
FORM-3

Display "Modify Department Name" form.

If you want to modify the department name then select "Modify


Department Name" from "Department" menu as shown in Figure.
Now a "Modify Department Name" form appears on the screen,
here select an existing department name and type the required
new department name as shown in Figure and click "Modify".
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form3: Display "Modify Department Name" form.
public partial class Form3 : Form
{
OleDbConnection DBCon1; // Database Connection 1

public Form3()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

~Form3()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will Display List of Department in Combobox1


private void Form3_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter1
OleDbDataAdapter DBAdapter1 = new
OleDbDataAdapter("select * from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();
}

//This Method Modify Department Name (selected from combobox1)


private void button1_Click(object sender, EventArgs e)
{
//Check if Existing and New Department Name Exist or not
if (comboBox1.SelectedValue != null &&
string.Compare(textBox1.Text, "") != 0)
{
// set DataBase Command1
OleDbCommand DBCom1 = new OleDbCommand("select
DEPT_NAME from department where dept_name= '" + textBox1.Text + "'",
DBCon1);
// Get Department Name from Database which already
exist
string DeptName = (string)DBCom1.ExecuteScalar();

//Dispose DataBase Command 2


DBCom1.Dispose();

//Check if New department name is already exist or not


if (string.Compare(DeptName, textBox1.Text.ToString())
== 0)
{
//New Department Name is alreasdy exist
MessageBox.Show(textBox1.Text + " already exist");
}
else
{
//Set DataBase Command 2
OleDbCommand DBCom2 = new OleDbCommand("update
department set dept_name='" + textBox1.Text.Trim() + "' where dept_id="
+ comboBox1.SelectedValue.ToString(), DBCon1);
//Excute DataBase Command 2
DBCom2.ExecuteNonQuery();
//Dispose DataBase Command 2
DBCom2.Dispose();

//Load Modified List of Department in Combobox1


//Get DataBase Adapter
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from department", DBCon1);

//Declare Data Set1


DataSet DS2 = new DataSet();

//Intialise IRecordCount to 0; IRecordCount is use


to store no. of record afected
int IRecordCount2 = 0;

//Fill DataBase Adapter1 and set IRecordCount


IRecordCount2 = DBAdapter2.Fill(DS2, "Department");

//Set Data Table1


DataTable DT2 = DS2.Tables["Department"];

//Set Data View1


DataView DV2 = DT2.DefaultView;

//set Combobox Data source to Data View 1


comboBox1.DataSource = DV2;

//Set DisplayMember and ValueMember of Combobox1


comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";

//Dispose DataTable1, DataSet1, DataBase Adapter 1


DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}
else if (comboBox1.SelectedValue == null)
{
MessageBox.Show("There is No Existing Department Exist
to modify");
}
else if (string.Compare(textBox1.Text, "") == 0)
{
MessageBox.Show("Please Enter New Department Name");
}

//Clear TextBox1
textBox1.Text = "";

}
}

}
FORM-4:

Display "Delete Department Name" form.

For deleting the department name, select "Delete Department


Name" from "Department" menu as shown in Figure. Now a
"Delete Department Name" form appears on the screen. Here
select a department name that is to be deleted and click "Delete"
as shown in Figure.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form4: Display "Delete Departemnt Name" form.
public partial class Form4 : Form
{
OleDbConnection DBCon1; // Database Connection 1

//This Constructor inititalse database connection


public Form4()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

//This destructor closes Database Connection 1


~Form4()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method loads department list in combobox1


private void Form4_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);

//Declare Data Set1


DataSet DS1 = new DataSet();

//Intialise IRecordCount to 0; IRecordCount is use to store


no. of record afected
int IRecordCount = 0;

//Fill DataBase Adapter1 and set IRecordCount


IRecordCount = DBAdapter1.Fill(DS1, "Department");

//Set Data Table1


DataTable DT1 = DS1.Tables["Department"];

//Set Data View1


DataView DV1 = DT1.DefaultView;

//set Combobox Data source to Data View 1


comboBox1.DataSource = DV1;

//Set DisplayMember and ValueMember of Combobox1


comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";

//Dispose DataTable1, DataSet1, DataBase Adapter 1


DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();
}

//This method will delete department name (which selected from


combobox1)
private void button1_Click(object sender, EventArgs e)
{
//Check if Existing Department Name Exist or not
if (comboBox1.SelectedValue != null)
{
// set DataBase Command1
OleDbCommand DBCom1 = new OleDbCommand("delete from
department where dept_id =" + comboBox1.SelectedValue.ToString(),
DBCon1);

//Execute Database Command1


DBCom1.ExecuteNonQuery();

//Delete DataBase Command1


DBCom1.Dispose();

//Show Messasge for Successful Deletion


MessageBox.Show("Department Name is Deleted");

//Load Modified List of Department in Combobox1


//Get DataBase Adapter
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from department", DBCon1);

//Declare Data Set2


DataSet DS2 = new DataSet();

//Intialise IRecordCount to 0; IRecordCount is use to


store no. of record afected
int IRecordCount = 0;

//Fill DataBase Adapter2 and set IRecordCount


IRecordCount = DBAdapter2.Fill(DS2, "Department");

//Set Data Table1


DataTable DT2 = DS2.Tables["Department"];

//Set Data View1


DataView DV2 = DT2.DefaultView;

//set Combobox Data source to Data View 2


comboBox1.DataSource = DV2;

//Set DisplayMember and ValueMember of Combobox1


comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";

//Dispose DataTable2, DataSet2, DataBase Adapter2


DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
else
{
MessageBox.Show("No Department Name Exist To Delete");
}
}
}

}
FORM-5

Display "Display Department Names" form.

To list all the departments that are currently present click


"Display Department Name List" from "Department" menu as
shown in Figure. Now a "Display Department List" form appears
on the screen. Here a list of departments will appear on the
screen as shown in Figure.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form5: Display "Display Department Names" form.
public partial class Form5 : Form
{
OleDbConnection DBCon1; // Database Connection 1
public Form5()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

~Form5()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This Method will load department list in datagridview1


private void Form5_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new
OleDbDataAdapter("select * from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set DataGridView Data source to Data View 1
dataGridView1.DataSource = DV1;
//Set DataGridView Column Name
dataGridView1.Columns[0].HeaderText = "Department ID";
dataGridView1.Columns[1].HeaderText = "Department
Name";
dataGridView1.Columns[1].Width = 225;
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();
}
}

}
FORM-6

STEP2- CREATE CLASS PER DEPARTMENT (CLASS MENU).

Display "New Class Name" form.

After creating the required departments you need to add new


classes to the departments. To add new classes, click the "Class"
menu and click "New Class Name". As shown in Figure.

Then "New Class Name" form is displayed on the screen. Here


first you have to select a department in which classes are to be
added, and type in the names of new classes on a new line each.
Once you typed the entire required class names click "Add" as
shown in Figure.

FORM-7

Display "Modify Class Name" form.

If you want to modify the existing class name then click "Modify
Class Name" from "Class" menu as shown in Figure. Now a "Modify
Class Name" form appears on the screen. Here select an existing
department name, class name and type the required new class
name as shown in Figure and click "Modify".
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form7: Display "Modify Class Name" form.
public partial class Form7 : Form
{
OleDbConnection DBCon1;
bool BDept;
public Form7()
{
InitializeComponent();
//Intialise New DataBase Connection 1
DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");
//Open DataBase Connection 1
DBCon1.Open();
//Set Department Flag to false
BDept = false;
}

~Form7()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will loads department and class list in combobox1


& combox2 respectively
private void Form7_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}

//This method will loads class list in combobox1 if another


department name is selected.
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Load List of Class in Combobox2 after filling combobox1
with list of department
if (comboBox1.SelectedValue != null && BDept == true)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}

//This method will modify class name


private void button1_Click(object sender, EventArgs e)
{
//Modify Class Name
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null &&
string.Compare(textBox1.Text.ToString(), "")!=0)
{
OleDbCommand DBCom1 = new OleDbCommand("select * from
class where class_name='" + textBox1.Text.ToString() + "' and dept_id
=" + comboBox1.SelectedValue.ToString(), DBCon1);
string SClass_name;
SClass_name = (string)DBCom1.ExecuteScalar();
DBCom1.Dispose();
if (string.Compare(SClass_name,
textBox1.Text.ToString()) == 0)
{
MessageBox.Show("Class Name =" +
textBox1.Text.ToString() + " is skiped because it is already exist");
textBox1.ResetText();
}
else
{
OleDbCommand DBCom2 = new OleDbCommand("update
class set class_name='" + textBox1.Text + "' where dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString(), DBCon1);
DBCom2.ExecuteNonQuery();
DBCom2.Dispose();
MessageBox.Show("Class Name is Modified");
textBox1.ResetText();

//Load List of Class in Combobox2 after filling


combobox1 with list of department
if (comboBox1.SelectedValue != null && BDept ==
true)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is
use to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of
Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase
Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}
}
else if (comboBox1.SelectedValue == null)
{
MessageBox.Show("No Department Name Exsit");
}
else if (comboBox2.SelectedValue == null)
{
MessageBox.Show("No Class Name Exsit");
}
else if (string.Compare(textBox1.Text.ToString(), "") == 0)
{
MessageBox.Show("Please Enter New Class Name");
}
}
}

FORM-8

Display "Delete Class Name" form.

Now if you want to delete a class from a department then Click


"Delete Class Name" from "Class" menu as shown in Figure. Now a
"Delete Class Name" form appears on the screen. Here select an
existing department name, class name and click "Delete" as shown
in Figure.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form8: Display "Delete Class Name" form.
public partial class Form8 : Form
{
OleDbConnection DBCon1;
bool BDept;
public Form8()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();

//Set Department Flag to false


BDept = false;
}

~Form8()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load departemnt and class list in combobox1


and combobox2 respectively.
private void Form8_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}

//This method will delete class name from database.


private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("Delete from
class where dept_id=" + comboBox1.SelectedValue.ToString() + " and
class_id=" + comboBox2.SelectedValue.ToString(), DBCon1);
DBCom1.ExecuteNonQuery();
DBCom1.Dispose();
MessageBox.Show("Class Name is Deleted");

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use
to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}
else if (comboBox1.SelectedValue == null)
{
MessageBox.Show("No Department Name Exsit");
}
else if (comboBox2.SelectedValue == null)
{
MessageBox.Show("No Class Name Exsit");
}
}
//This method will load Class list in combobox2 if department
name is changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Load List of Class in Combobox2 after filling combobox1
with list of department
if (comboBox1.SelectedValue != null && BDept == true)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}
}

}
FORM-9

Display "Display Class Names" form.

To list all the classes in a department then select "Display Class


Names" from "Class" menu as shown in Figure. Now a "Display
Class Names" form appears on the screen. Here select a
department name, a list of all the classes related to that
department will appear on the screen as shown in Figure.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form9: Display "Display Class Names" form.
public partial class Form9 : Form
{
OleDbConnection DBCon1;
bool BDept;

public Form9()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();

//Set Department Flag to false


BDept = false;
}

~Form9()
{
//Close DataBase Connection 1
DBCon1.Close();
}
//This method will load Department and class list in combobox1
and datagridview1 respectively.
private void Form9_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select class_name from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;

//Fill Data Grid View1


dataGridView1.DataSource = DV2;
dataGridView1.Columns[0].HeaderText = "Class Name";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}

//This method will load class list in datagridview1 if


Department Name is changed.
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Load List of Class in Combobox2
if (comboBox1.SelectedValue != null && BDept==true)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select class_name from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;

//Fill Data Grid View1


dataGridView1.DataSource = DV2;
dataGridView1.Columns[0].HeaderText = "Class Name";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}
}

}
FORM-10

Step3. Add Lecturer in Department.

The “Lecturer” menu shown in Figure. It let you to add, modify,


delete, and display the lecturers in a department.

In this menu we first click “New Lecturer Name” as shown in


Figure .On clicking, “New Lecturer Name” form is displayed on
the screen. In this form we first select the department in which
the Lecturer(s) to be added. Then we enter the new lecturers’
name on a new line each, as shown in the figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form10: Display "New Lecturer Name" form.
public partial class Form10 : Form
{
OleDbConnection DBCon1; // Database Connection 1
int IMLect_ID;

public Form10()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Intialise Max Class id to 0;


IMLect_ID = 0;

//Open DataBase Connection 1


DBCon1.Open();
}

~Form10()
{
//Close DataBase Connection 1
DBCon1.Close();
}
//This method will load Department List in Combobox1 & retrive
Max Lecturer Id from database
private void Form10_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Get MAximum Lecturer ID as Per Department


if (comboBox1.SelectedValue != null)
{
//string SDeptID;
OleDbCommand DBCom0;
//OleDbDataReader DBRead0;
DBCom0 = new OleDbCommand("SELECT MAX(LECT_ID) AS Expr1
FROM Lecturer" , DBCon1);
try
{
IMLect_ID = (int)DBCom0.ExecuteScalar();
DBCom0.Dispose();
}
catch (System.NullReferenceException)
{
IMLect_ID = 0;
DBCom0.Dispose();
}
catch (System.InvalidCastException)
{
IMLect_ID = 0;
}

IMLect_ID++;
}
}

//This Method will add new Lecturer name in department


private void button1_Click(object sender, EventArgs e)
{
//Initialise RichTextBox Lines Counter
int IRTBLine = 0;

for (IRTBLine = 0; IRTBLine < richTextBox1.Lines.Length;


IRTBLine++)
{

if (string.Compare(richTextBox1.Lines[IRTBLine], "") !=
0)
{
OleDbCommand DBCom1;
DBCom1 = new OleDbCommand("select lect_name from
lecturer where lect_name='" + richTextBox1.Lines[IRTBLine] + "' and
dept_id =" + comboBox1.SelectedValue.ToString(), DBCon1);

string SLect_name;
SLect_name = (string)DBCom1.ExecuteScalar();
DBCom1.Dispose();
if (string.Compare(SLect_name,
richTextBox1.Lines[IRTBLine].ToString()) == 0)
{
MessageBox.Show("Lecturer Name =" +
richTextBox1.Lines[IRTBLine] + " is skiped because it is already
exist");
}
else
{
//MessageBox.Show("insert into Lecturer
values(" + comboBox1.SelectedValue.ToString() + "," + IMLect_ID + ",'"
+ richTextBox1.Lines[IRTBLine].ToString() + "')");
OleDbCommand DBCom2 = new OleDbCommand("insert
into Lecturer values(" + comboBox1.SelectedValue.ToString() + "," +
IMLect_ID + ",'" + richTextBox1.Lines[IRTBLine].ToString() + "')",
DBCon1);
DBCom2.ExecuteNonQuery();
DBCom2.Dispose();
IMLect_ID++;
}
}
}

//Clear RichTextBox1
richTextBox1.ResetText();
}
}
}
Form-11

Display "Modify Lecturer Name" form.

To modify a lecturer we click “Modify Lecturer Name”. It


displays a form titled as ”Modify Lecturer” in this we have to
first select the Department name & Existing Lecturer Name then
type the New Lecturer Name & click “Modify”. As shown in
Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form11: Display "Modify Lecturer Name" form.
public partial class Form11 : Form
{
OleDbConnection DBCon1; // Database Connection 1
bool BDept;
public Form11()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");
//Open DataBase Connection 1
DBCon1.Open();
//Set Department Flag to false
BDept = false;
}

~Form11()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department and Lecturer list in


combobox1 and combobox2 respectively.
private void Form11_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Lecturer in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Lecturer");
//Set Data Table1
DataTable DT2 = DS2.Tables["Lecturer"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "LECT_NAME";
comboBox2.ValueMember = "LECT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}

//This method will modify lecturer name


private void button1_Click(object sender, EventArgs e)
{
//Modify Lecturer Name
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null &&
string.Compare(textBox1.Text.ToString(), "") != 0)
{
OleDbCommand DBCom1 = new OleDbCommand("select * from
Lecturer where Lect_name='" + textBox1.Text.ToString() + "' and dept_id
=" + comboBox1.SelectedValue.ToString(), DBCon1);
string SLect_name;
SLect_name = (string)DBCom1.ExecuteScalar();
DBCom1.Dispose();
if (string.Compare(SLect_name,
textBox1.Text.ToString()) == 0)
{
MessageBox.Show("Lecturer Name =" +
textBox1.Text.ToString() + " is skiped because it is already exist");
textBox1.ResetText();
}
else
{
OleDbCommand DBCom2 = new OleDbCommand("update
Lecturer set Lect_name='" + textBox1.Text + "' where dept_id=" +
comboBox1.SelectedValue.ToString() + " and Lect_id=" +
comboBox2.SelectedValue.ToString(), DBCon1);
DBCom2.ExecuteNonQuery();
DBCom2.Dispose();
MessageBox.Show("Lecturer Name is Modified");
textBox1.ResetText();

//Load List of Class in Combobox2 after filling


combobox1 with list of department
if (comboBox1.SelectedValue != null && BDept ==
true)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is
use to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2,
"Lecturer");
//Set Data Table1
DataTable DT2 = DS2.Tables["Lecturer"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of
Combobox1
comboBox2.DisplayMember = "LECT_NAME";
comboBox2.ValueMember = "LECT_ID";
//Dispose DataTable1, DataSet1, DataBase
Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}
}
else if (comboBox1.SelectedValue == null)
{
MessageBox.Show("No Department Name Exsit");
}
else if (comboBox2.SelectedValue == null)
{
MessageBox.Show("No Lecturer Name Exsit");
}
else if (string.Compare(textBox1.Text.ToString(), "") == 0)
{
MessageBox.Show("Please Enter New Lecturer Name");
}
}

//This method will loads lecturer list in combobox2 if another


department name is selected
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Load List of Lecturer in Combobox2
if (comboBox1.SelectedValue != null && BDept == true)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Lecturer");
//Set Data Table1
DataTable DT2 = DS2.Tables["Lecturer"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "LECT_NAME";
comboBox2.ValueMember = "LECT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

}
}

Form-12

Display "Delete Lecturer Name" form.


If you require deleting a lecturer from the existing lecturers
then click “Delete Lecturer Name” from the “Lecturer” menu as
shown in Figure. Then a “Delete Lecturer Name” form is
displayed. Here we select the Department Name & Lecturer
Name to be deleted and click “Delete”, as shown in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form12: Display "Delete Lecturer Name" form
public partial class Form12 : Form
{
OleDbConnection DBCon1;
bool BDept;
public Form12()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();

//Set Department Flag to false


BDept = false;
}

~Form12()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department and Class list in combobox1


and combobox2 respectively
private void Form12_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Lecturer");
//Set Data Table1
DataTable DT2 = DS2.Tables["Lecturer"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "LECT_NAME";
comboBox2.ValueMember = "LECT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

//This method will delete lecturer name from database


private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("Delete from
Lecturer where dept_id=" + comboBox1.SelectedValue.ToString() + " and
Lect_id=" + comboBox2.SelectedValue.ToString(), DBCon1);
DBCom1.ExecuteNonQuery();
DBCom1.Dispose();
MessageBox.Show("Lecturer Name is Deleted");

//Get DataBase Adapter2


OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);

//Declare Data Set2


DataSet DS2 = new DataSet();

//Intialise IRecordCount to 0; IRecordCount is use to


store no. of record afected
int IRecordCount2 = 0;

//Fill DataBase Adapter1 and set IRecordCount


IRecordCount2 = DBAdapter2.Fill(DS2, "Lecturer");

//Set Data Table1


DataTable DT2 = DS2.Tables["Lecturer"];

//Set Data View1


DataView DV2 = DT2.DefaultView;

//set Combobox Data source to Data View 1


comboBox2.DataSource = DV2;

//Set DisplayMember and ValueMember of Combobox1


comboBox2.DisplayMember = "LECT_NAME";

comboBox2.ValueMember = "LECT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();

private void comboBox1_SelectedIndexChanged(object sender,


EventArgs e)
{
//Load List of Lecturer in Combobox2
if (comboBox1.SelectedValue != null && BDept == true)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Lecturer");
//Set Data Table1
DataTable DT2 = DS2.Tables["Lecturer"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "LECT_NAME";
comboBox2.ValueMember = "LECT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

}
}

}
Form-13

Display "Display Lecturer Name" form.


Finally to display list of the lecturers in a particular department,
we click “Display Lecturers Names” from the “Lecturer” menu as
shown in Figure. A new form titled “Display Lecturer Name” is
displayed on the screen. Here we select the Department Name
and the list of all the lecturers in the department are displayed
as shown in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Attendance
{
//Form 13: Display " Display Lecturer Name form".
public partial class Form13 : Form
{
OleDbConnection DBCon1;
bool BDept;

public Form13()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();

//Set Department Flag to false


BDept = false;
}

~Form13()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will oads Department and Lecturer list in


combobox1 and datagridview1 resectively.
private void Form13_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select Lect_name from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Lecturer");
//Set Data Table1
DataTable DT2 = DS2.Tables["Lecturer"];
//Set Data View1
DataView DV2 = DT2.DefaultView;

//Fill Data Grid View1


dataGridView1.DataSource = DV2;
dataGridView1.Columns[0].HeaderText = "Lecturer Name";
dataGridView1.Columns[0].Width = 225;
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
}

//This method will loads Lecturer list in Datagridview1 if


department name is changed.
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Load List of Class in Combobox2
if (comboBox1.SelectedValue != null && BDept == true)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select Lect_name from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Lecturer");
//Set Data Table1
DataTable DT2 = DS2.Tables["Lecturer"];
//Set Data View1
DataView DV2 = DT2.DefaultView;

//Fill Data Grid View1


dataGridView1.DataSource = DV2;
dataGridView1.Columns[0].HeaderText = "Lecturer Name";
dataGridView1.Columns[0].Width = 225;
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

}
}

Form-14

Step4. Add Subject in Class.


Display "New Subject Name" form.

After creating Departments, Classes and Lecturers, you can now


add Subjects to this application using the “Subject” menu, as
shown in Figure.
Now to add new subject to the class you have to select the
"Subject" menu and click "New Subject Name" as shown in Figure

To add new subjects we click the “Subject” menu & click on the
“New Subject Name”. Next, you can see “New Subject Name
form in which you have to select Department Name, Class Name
and Semester, and then enter the Subjects to be added, each on
a new line. Finally click “Add” to add the new subject(s). As shown
in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form14: Display " New Subject Name" form.
public partial class Form14 : Form
{
OleDbConnection DBCon1;
bool BDept;
int ISub_Ind;

public Form14()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");
//Open DataBase Connection 1
DBCon1.Open();
//Set Department Flag to false
BDept = false;
//Initialise ISub_Ind Counter
ISub_Ind = 0;

~Form14()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class and Semester List in


combobox1, combobox2 & combobox3 respectively and
// retrive maximum subject id from database
private void Form14_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

//Load Semester List in Combobox3


//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();

//Generate next Subject Inedex

OleDbCommand DBCom1 = new OleDbCommand("SELECT MAX(SUB_IND)


AS Expr1 FROM SUBJECT", DBCon1);
try
{
ISub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
ISub_Ind = 0;
}
catch (System.InvalidCastException)
{
ISub_Ind = 0;
}
ISub_Ind++;
DBCom1.Dispose();

//This method will load class list in combobox2 if dapartment


name is changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (comboBox1.SelectedValue != null && BDept == true)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
else if (comboBox1.SelectedValue == null && BDept == true)
{
MessageBox.Show("No Department Exist");
}
}

//This method will add new subject name


private void button1_Click(object sender, EventArgs e)
{
int IRTB_Linec = 0;
string SSub_name;
for (IRTB_Linec = 0; IRTB_Linec <
richTextBox1.Lines.Length; IRTB_Linec++)
{
if (string.Compare(richTextBox1.Lines[IRTB_Linec],
"") != 0)
{
OleDbCommand DBCom2 = new OleDbCommand("select
sub_name from subject where sub_name='" +
richTextBox1.Lines[IRTB_Linec] + "' and dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
SSub_name = (string)DBCom2.ExecuteScalar();
DBCom2.Dispose();
if (string.Compare(richTextBox1.Lines[IRTB_Linec],
SSub_name) != 0)
{
OleDbCommand DBCom3 = new OleDbCommand("insert
into subject values(" + comboBox1.SelectedValue.ToString() + "," +
comboBox2.SelectedValue.ToString() + "," +
comboBox3.SelectedValue.ToString() + "," + ISub_Ind + ",'" +
richTextBox1.Lines[IRTB_Linec].ToString() + "')", DBCon1);
DBCom3.ExecuteNonQuery();
ISub_Ind++;
DBCom3.Dispose();
}
else
{
MessageBox.Show("Subject Already exist");
} } }
//Clear Rich Text Box
richTextBox1.ResetText(); } } }
form-15
Display "Modify Subject Name" form.

Similarly, to modify a subject, click on the “Modify Subject


Name” in the “Subject” menu as shown in Figure. Further to
modify the subject name we select Department Name, Class
Name, Semester, Existing Subject Name and type in the New
Subject Name & click “Modify” as shown in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form15: Display "Modify Subject Name" form.
public partial class Form15 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;
bool BSem;

public Form15()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();

//Set Department Flag to false


BDept = false;

//set Class Flag to false


BClass = false;

//set Semester Flag to false


BSem = false;
}

~Form15()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class, Semester & Subject


List in combobox1, combobox2, combobox3 & combobox4 respectively
private void Form15_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load Semester List in Combobox3


//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();

//set Semester Flag to True


BSem = true;

//Load subject List in Combobox4


//Get DataBase Adapter4
try
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
catch (System.NullReferenceException)
{
MessageBox.Show("Department Doesn't Exists");
}
}

//This method will load Class and Subject List in combobox2 &
combobox4 respectively if department name is changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (comboBox1.SelectedValue != null && BDept == true)
{
//set Class flag to false
BClass = false;
//Load Class List in Combobox2
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();

//set Class flag to false


BClass = true;

//Load subject List in Combobox4


//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
else if (comboBox1.SelectedValue == null && BDept == true)
{
MessageBox.Show("No Department Exist");
}
}

//This method will load Subject List in combobox4 if class name


is changed
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
BClass == true)
{
//Load subject List in Combobox4
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
}

//This method will load Subject List in combobox4 if semester


name is changed
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
BSem == true)
{
//Load subject List in Combobox4
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
}

//This Method will modify Subject Name.


private void button1_Click(object sender, EventArgs e)
{
string SSub_name;
if (string.Compare(textBox1.Text.ToString(), "") != 0)
{
OleDbCommand DBCom2 = new OleDbCommand("select sub_name
from subject where sub_name='" + textBox1.Text.ToString() + "' and
dept_id =" + comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
SSub_name = (string)DBCom2.ExecuteScalar();
DBCom2.Dispose();
if (string.Compare(textBox1.Text.ToString(), SSub_name)
!= 0)
{
OleDbCommand DBCom3 = new OleDbCommand("update
subject set sub_name='" + textBox1.Text.ToString() + "' where sub_ind
=" + comboBox4.SelectedValue.ToString(), DBCon1);
DBCom3.ExecuteNonQuery();
DBCom3.Dispose();
}
else
{
MessageBox.Show("Subject Already exist");
}
}
else
{
MessageBox.Show("Please Enter Modified Subject Name");
}

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
BSem == true)
{
//Load subject List in Combobox4
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
}
}

Form-16

Display "Delete Subject Name" form.


If you require deleting a subject from the existing subjects then
click “Delete Subject Name” from the “Subject” menu as shown
in Figure. Then a “Delete Subject Name” form is displayed. Here
we select the Department Name, Class Name, Semester, Subject
Name and click the “Delete”, as shown in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form16: Display "Delete Subject Name" form.
public partial class Form16 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;

public Form16()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();

//Set Department Flag to false


BDept = false;
//Set Class Flag to false
BClass = false;
}

~Form16()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class, Semester & Subject


List in combobox1, combobox2, combobox3 & combobox4 respectively
private void Form16_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

//Set Class Flag to true


BClass = true;

//Load Semester List in Combobox3


//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from Subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount4 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter4 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox1
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
}

//This method will load Class & Subject List in combobox2 &
combobox4 if another department name is selected
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (comboBox1.SelectedValue != null && BDept == true)
{
//Set Class Flag to false
BClass = false;
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
//Set Class Flag to true
BClass = true;
}
else if (comboBox1.SelectedValue == null && BDept == true)
{
MessageBox.Show("No Department Exist");
}

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
BDept == true)
{
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from Subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount4 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter4 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox1
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
}

//This method will load Subject List in combobox4 if class name


is changed
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
BClass == true)
{
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from Subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount4 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter4 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox1
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
}

//This method will load Subject List in combobox4 if semester


name is changed
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from Subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount4 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter4 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox1
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}

//This Method will delete Subject name from database & reload
subject list in combobox4
private void button1_Click(object sender, EventArgs e)
{
if (comboBox4.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("Delete from
Subject where Dept_id =" + comboBox1.SelectedValue.ToString() + " and
Class_id =" + comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString() + " and sub_ind=" +
comboBox4.SelectedValue.ToString(), DBCon1);
DBCom1.ExecuteNonQuery();
MessageBox.Show("Subject is Delated");
}
else
{
MessageBox.Show("No Subject Exist");
}

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from Subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount4 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter4 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox1
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}

}
}

}
Form-17

Display "Display Subject Names" form.

Finally to display list of subject in a particular department, we


click “Display Subject Names” from the “Subject” menu as shown
in Figure. The “Display Subject Names” form is displayed on the
screen. Here we select the Department Name, Class Name & the
Semester and the list of all the subjects is displayed as
automatically, shown in Figure.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form17: Display "Display Subject Names" form.
public partial class Form17 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;

public Form17()
{
InitializeComponent();
//Intialise New DataBase Connection 1
DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");
//Open DataBase Connection 1
DBCon1.Open();
//Set Department Flag to false
BDept = false;
//Set Class Flag to false
BClass = false;
}

~Form17()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class, Semester and Subject


List in combobox1, combobox2, combobox3 & datagridview1 respectively
private void Form17_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

//Set Class Flag to True


BClass = true;

//Load Semester List in Combobox3


//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();

//Load Subject List in Data Grid View 1


if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select Sub_name from Subject where Dept_id =" +
comboBox1.SelectedValue.ToString() + " and Class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount4 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter4 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;

//Fill Data Grid View1


dataGridView1.DataSource = DV4;
dataGridView1.Columns[0].HeaderText = "Subject Name";
dataGridView1.Columns[0].Width = 255;
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}

//This method will load Class and subject List in combobox2 &
datagridview1 respectively if another department name is selected
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (comboBox1.SelectedValue != null && BDept == true)
{
//Set Class Flag to flass
BClass = false;

//Get DataBase Adapter2


OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();

//Set Class Flag to True


BClass = true;

}
else if(comboBox1.SelectedValue == null && BDept == true)
{
MessageBox.Show("No Department Exist");
}

//Load Subject List in Data Grid View 1


if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
BDept == true)
{
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select Sub_name from Subject where Dept_id =" +
comboBox1.SelectedValue.ToString() + " and Class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount4 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter4 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;

//Fill Data Grid View1


dataGridView1.DataSource = DV4;
dataGridView1.Columns[0].HeaderText = "Subject Name";
dataGridView1.Columns[0].Width = 255;
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
}

//This method will load Class and subject List in combobox2 &
datagridview1 respectively if another class name is selected

private void comboBox2_SelectedIndexChanged(object sender,


EventArgs e)
{
//Load Subject List in Data Grid View 1
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
BClass == true)
{
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select Sub_name from Subject where Dept_id =" +
comboBox1.SelectedValue.ToString() + " and Class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount4 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter4 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;

//Fill Data Grid View1


dataGridView1.DataSource = DV4;
dataGridView1.Columns[0].HeaderText = "Subject Name";
dataGridView1.Columns[0].Width = 255;
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
}

//This method will load Class and subject List in combobox2 &
datagridview1 respectively if another semester name is selected
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
//Load Subject List in Data Grid View 1
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
BClass == true)
{
//Get DataBase Adapter4
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select Sub_name from Subject where Dept_id =" +
comboBox1.SelectedValue.ToString() + " and Class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount4 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter4 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;

//Fill Data Grid View1


dataGridView1.DataSource = DV4;
dataGridView1.Columns[0].HeaderText = "Subject Name";
dataGridView1.Columns[0].Width = 255;
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
}
}
}
Form-18

Step5. Add Student in Class.

Display "New Student Name" form.

The main purpose of this application is to analyze the attendance


of each student. Thus it denotes that the students’ name must be
added to this system. The first thing is to add the students in a
class under a particular department. Thus we click “New Student
Name” in “Student” menu as shown in Figure. Further you see a
“New Student Name” form. In this form you have to first select
the Department Name, Class Name and add the student(s) name.
Besides this you will find the Roll No. of the currently added
student & the Maximum using System; Roll No of students that
are already present. Then click “Add” to add the new students, as
shown in Figure.

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{

//Form18: Display "New Student Name" form


public partial class Form18 : Form
{
OleDbConnection DBCon1;
bool BDept;
static bool BClass;
int IMStu_ID;

public Form18()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Intialise Max Student ID to 0;


IMStu_ID = 0;

//Set Depatment Flag to false


BDept = false;

//Open DataBase Connection 1


DBCon1.Open();
}

~Form18()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class List in combobox1,


combobox2 respectively and
//Retrive max student id from database
private void Form18_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Class Flag to false


BClass = false;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

//Set Class Flag to true


BClass = true;
//Set Department Flag to true
BDept = true;

//Get Maximum Student ID in Class

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("SELECT
MAX(STUDENT_ID) AS Expr1 FROM STUDENT WHERE DEPT_ID =" +
comboBox1.SelectedValue.ToString() + " AND CLASS_ID =" +
comboBox2.SelectedValue.ToString(), DBCon1);

int IStud_ID=0;
try
{
IStud_ID = (int) DBCom1.ExecuteScalar();

}
catch (System.InvalidCastException)
{
IStud_ID = 0;
}

label7.Text = IStud_ID.ToString();
IMStu_ID = IStud_ID + 1;
}
//
}

////This method will load Class List in combobox2 and retrive


max student_id form database if Department name is changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Set Class Flag to false
BClass = false;

if (comboBox1.SelectedValue != null && BDept == true)


{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
else if (comboBox1.SelectedValue == null && BDept == true)
{
MessageBox.Show("No Department Exist");
}

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && BDept==true)
{
OleDbCommand DBCom1 = new OleDbCommand("SELECT
MAX(STUDENT_ID) AS Expr1 FROM STUDENT WHERE DEPT_ID =" +
comboBox1.SelectedValue.ToString() + " AND CLASS_ID =" +
comboBox2.SelectedValue.ToString(), DBCon1);

int IStud_ID = 0;
try
{
IStud_ID = (int)DBCom1.ExecuteScalar();

}
catch (System.InvalidCastException)
{
IStud_ID = 0;
}

label7.Text = IStud_ID.ToString();
IMStu_ID = IStud_ID + 1;
}
//Set Class Flag to True
BClass = true;
}

private void richTextBox1_TextChanged(object sender, EventArgs


e)
{

int IRTB_Linec = 0;
int ICount = 0;
int ICNum = 0;
for (IRTB_Linec = 0; IRTB_Linec <
richTextBox1.Lines.Length; IRTB_Linec++)
{

if (string.Compare(richTextBox1.Lines[IRTB_Linec],
"") != 0)
{
ICount = IMStu_ID + ICNum;
label5.Text = ICount.ToString();
ICNum++;
}
}
}

//Retrive max student_id form database if Class name is changed


private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{

if (BClass == true && comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("SELECT
MAX(STUDENT_ID) AS Expr1 FROM STUDENT WHERE DEPT_ID =" +
comboBox1.SelectedValue.ToString() + " AND CLASS_ID =" +
comboBox2.SelectedValue.ToString(), DBCon1);
string SStud_ID;
int IStud_ID = 0;
try
{
SStud_ID = (string)DBCom1.ExecuteScalar();
IStud_ID = Int32.Parse(SStud_ID);
}
catch (System.InvalidCastException)
{
IStud_ID = 0;
}

label7.Text = IStud_ID.ToString();
IMStu_ID = IStud_ID + 1;
}
}

//Add new student in database


private void button1_Click(object sender, EventArgs e)
{
int IRTBLinec = 0;
for (IRTBLinec = 0; IRTBLinec < richTextBox1.Lines.Length;
IRTBLinec++)
{
if (string.Compare(richTextBox1.Lines[IRTBLinec], "") !
= 0)
{
string SStud_name;
OleDbCommand DBCom1 = new OleDbCommand("select
student_name from student where student_name='" +
richTextBox1.Lines[IRTBLinec].ToString() + "' and dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString(),DBCon1 );
SStud_name = (string)DBCom1.ExecuteScalar();
DBCom1.Dispose();
if (string.Compare(SStud_name,
richTextBox1.Lines[IRTBLinec].ToString()) != 0)
{
OleDbCommand DBCom2 = new OleDbCommand("insert
into student values(" + comboBox1.SelectedValue.ToString() + "," +
comboBox2.SelectedValue.ToString() + "," + IMStu_ID + ",'" +
richTextBox1.Lines[IRTBLinec].ToString() + "')", DBCon1);
DBCom2.ExecuteNonQuery();
DBCom2.Dispose();
IMStu_ID++;
}
}
}
int ITemp = IMStu_ID - 1;
label7.Text = ITemp.ToString();
richTextBox1.ResetText();
}
}
}
Form-19

Display "Modify Student Name" form.

If required, now you can also modify a student name for this,
click “Modify Student Name” in the “Student” menu. As shown in
Figure. A “Modify Student Name” form appears on the screen. In
this form you have to select the Department Name, Class Name
and then enter the Roll No. of the existing student. The name of
existing student is automatically displayed. Then type in the New
Student Name and click “Modify”, as shown in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form19: Display "Modify Student Name" form
public partial class Form19 : Form
{
OleDbConnection DBCon1;
bool BDept;

public Form19()
{
InitializeComponent();
//Intialise New DataBase Connection 1
DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");
//Set Depatment Flag to false
BDept = false;
//Open DataBase Connection 1
DBCon1.Open();
}

~Form19()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department and Class List in combobox1


and combobox2 respectively
private void Form19_Load(object sender, EventArgs e)
{
maskedTextBox1.Text = "";
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//Set Department Flag to true
BDept = true;
}

//This method will load class list in combobox2 if another


department is selected
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Set Class Flag to false
maskedTextBox1.Text = "";

if (comboBox1.SelectedValue != null && BDept == true)


{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
else if (comboBox1.SelectedValue == null && BDept == true)
{
MessageBox.Show("No Department Exist");
}

//This method wil display student name in textbox1 as per


student_id in Maskedtextbox1
private void maskedTextBox1_TextChanged(object sender,
EventArgs e)
{
string SStud_Name="";
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && string.Compare(maskedTextBox1.Text,
"") != 0)
{
OleDbCommand DBCom1 = new OleDbCommand("select
Student_Name from student where student_id="+
maskedTextBox1.Text.ToString() +" and dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString(), DBCon1);

try
{
SStud_Name = (string)DBCom1.ExecuteScalar();

}
catch (System.NullReferenceException)
{
SStud_Name= "";
}

DBCom1.Dispose();
}

if (string.Compare(SStud_Name, "") != 0)
{
textBox1.Text = SStud_Name;
}
else
{
textBox1.Text = "";
}
}

//This method will modify student Name


private void button1_Click(object sender, EventArgs e)
{
int a1 = string.Compare(textBox1.Text.Trim(), "");
int a2 = string.Compare(textBox2.Text.Trim(), "");
if (a1 != 0 && a2 != 0)
{
OleDbCommand DBCom2 = new OleDbCommand("update student
set student_name='" + textBox2.Text.Trim() + "' where student_id=" +
maskedTextBox1.Text.Trim() + "and dept_id=" +
comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString(), DBCon1);
DBCom2.ExecuteNonQuery();
MessageBox.Show("Student Name is Updated");
maskedTextBox1.Text = "";
textBox1.Text = "";
textBox2.Text = "";
}
else if (a1 == 0)
{
MessageBox.Show("No Student Selected (Invalid Student
ID)");
}
else if (a2 == 0)
{
MessageBox.Show("Please Enter New Student Name");
}
}

private void comboBox2_SelectedIndexChanged(object sender,


EventArgs e)
{
maskedTextBox1.Text = "";
}
}

Form-20

Display "Delete Student Name" form.

To delete a student name from the particular class under a


department, click on “Delete Student Name” from the “Student”
menu, as shown in “Figure”. A form titled as” Delete Student
Name” is displayed on the screen. Here you have to select the
Department Name, Class Name, enter the Roll No. of the existing
student. The name of the student automatically gets displayed.
Now click ”Delete” to delete the student name, as shown in
Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form20: Display "Delete Student Name" form
public partial class Form20 : Form
{
OleDbConnection DBCon1;
bool BDept;

public Form20()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Set Depatment Flag to false


BDept = false;

//Open DataBase Connection 1


DBCon1.Open();
}

~Form20()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load departemnt and class list in combobox1


and combobox2 respectively
private void Form20_Load(object sender, EventArgs e)
{
maskedTextBox1.Text = "";
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

//Set Department Flag to true


BDept = true;

//This method will load class list in combobox2 respectively


private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Set Class Flag to false
maskedTextBox1.Text = "";

if (comboBox1.SelectedValue != null && BDept == true)


{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
else if (comboBox1.SelectedValue == null && BDept == true)
{
MessageBox.Show("No Department Exist");
}

private void comboBox2_SelectedIndexChanged(object sender,


EventArgs e)
{
maskedTextBox1.Text = "";
}

private void maskedTextBox1_TextChanged(object sender,


EventArgs e)
{
string SStud_Name = "";
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && string.Compare(maskedTextBox1.Text,
"") != 0)
{
OleDbCommand DBCom1 = new OleDbCommand("select
Student_Name from student where student_id=" +
maskedTextBox1.Text.ToString() + " and dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString(), DBCon1);

try
{
SStud_Name = (string)DBCom1.ExecuteScalar();

}
catch (System.NullReferenceException)
{
SStud_Name = "";
}

DBCom1.Dispose();
}

if (string.Compare(SStud_Name, "") != 0)
{
textBox1.Text = SStud_Name;
}
else
{
textBox1.Text = "";
}
}

//This method will delete student Name


private void button1_Click(object sender, EventArgs e)
{

if (string.Compare(textBox1.Text.Trim(), "") != 0)
{
OleDbCommand DBCom1 = new OleDbCommand("Delete from
student where student_id=" + maskedTextBox1.Text.Trim() + "and
dept_id=" + comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString(), DBCon1);
DBCom1.ExecuteNonQuery();
MessageBox.Show("Student Name is Deleted");
maskedTextBox1.Text = "";
textBox1.Text = "";
}
else
{
MessageBox.Show("No Student Selected (Invalid Student
ID)");
}
}
}
}

Form-21

Display "Display Student Names" form.


Like departments and class, you can also retrieve the list of the
students. Click on the “Display Student Names” in the “Student”
menu. As shown in Figure. Next, a “Display Student Names” form
is displayed, in this you have to first select the Department
Name and Class Name, the list of all the students of the selected
class under the selected department is displayed in the form, as
shown in the Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form21: Display "Display Student Names" form
public partial class Form21 : Form
{
OleDbConnection DBCon1;
bool BDept;
static bool BClass;

public Form21()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Set Depatment Flag to false


BDept = false;

//Open DataBase Connection 1


DBCon1.Open();
}

~Form21()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load department, class and student list in


combobox1, comboboc2 and datagridview1 respectively
private void Form21_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Class Flag to false


BClass = false;

//Load List of Class in Combobox2


if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable2, DataSet2, DataBase Adapter 2
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}

//Set Class Flag to true


BClass = true;
//Set Department Flag to true
BDept = true;

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null)
{
OleDbDataAdapter DBAdapter3 = new
OleDbDataAdapter("select student_id, student_name from student where
dept_id =" + comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString(), DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Student");
//Set Data Table3
DataTable DT3 = DS3.Tables["Student"];
//Set Data View3
DataView DV3 = DT3.DefaultView;

//Set Data in Data Grid View 1

dataGridView1.DataSource = DV3;
dataGridView1.Columns[0].HeaderText = "Student Roll
No.";
dataGridView1.Columns[1].HeaderText = "Student Name";

dataGridView1.Columns[0].Width = 150;
dataGridView1.Columns[1].Width = 225;

//Dispose DataTable3, DataSet3, DataBase Adapter3


DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();

}
}
//This method will load class and student list in comboboc2 and
datagridview1 respectively if another department is selected
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Set Class Flag to false
BClass = false;

if (comboBox1.SelectedValue != null && BDept == true)


{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
else if (comboBox1.SelectedValue == null && BDept == true)
{
MessageBox.Show("No Department Exist");
}

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && BDept == true)
{
OleDbDataAdapter DBAdapter3 = new
OleDbDataAdapter("select student_id, student_name from student where
dept_id =" + comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString(), DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Student");
//Set Data Table3
DataTable DT3 = DS3.Tables["Student"];
//Set Data View3
DataView DV3 = DT3.DefaultView;

//Set Data in Data Grid View 1

dataGridView1.DataSource = DV3;
dataGridView1.Columns[0].HeaderText = "Student Roll
No.";
dataGridView1.Columns[1].HeaderText = "Student Name";

dataGridView1.Columns[0].Width = 150;
dataGridView1.Columns[1].Width = 225;

//Dispose DataTable3, DataSet3, DataBase Adapter3


DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();

BClass = true;
}

//This method will load student list in datagridview1 if


another class is selected
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BClass == true && comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null)
{
OleDbDataAdapter DBAdapter3 = new
OleDbDataAdapter("select student_id, student_name from student where
dept_id =" + comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString(), DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Student");
//Set Data Table3
DataTable DT3 = DS3.Tables["Student"];
//Set Data View3
DataView DV3 = DT3.DefaultView;

//Set Data in Data Grid View 1

dataGridView1.DataSource = DV3;
dataGridView1.Columns[0].HeaderText = "Student Roll
No.";
dataGridView1.Columns[1].HeaderText = "Student Name";

dataGridView1.Columns[0].Width = 150;
dataGridView1.Columns[1].Width = 225;

//Dispose DataTable3, DataSet3, DataBase Adapter3


DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();
}
}
}

Form-22

Step6. Register Lecturer.

Display "Register Lecturer Name for a Subject" form.


To register lecturer name click "Register Lecturer Name for a
Subject" from "Lecturer Registration" under “Registration” menu
as shown in Figure. Then, "Register Lecturer Name for a Subject"
form is displayed. Here you have to first select Department
Name, Class Name, Semester, Subject Name, and Lecturer Name
and than click on "Register" to register a lecturer for the
required subject, as shown in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Attendance
{
//Form22: Display "Register Lecturer Name for a Subject" form
public partial class Form22 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;
bool BSem;
bool BSub;
bool BLect;
int IMRegSInd;

public Form22()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();

//Intialise Maximum Register Subject Index


IMRegSInd = 0;

~Form22()
{
//Close DataBase Connection 1
DBCon1.Close();
}

////This method will load Department, Class, Semester, Subject


and Lecturer List in combobox1, combobox2, combobox3, combobox4 &
combobox5 respectively
//and retrive max registered subject id from database
private void Form22_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
BDept = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load Semester List in Combobox3


BSem = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();
//set Semester Flag to True
BSem = true;

//Load List of Class in Combobox2


BClass = false;

if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;
//Load List of Lecturer in Combobox2
BLect = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
BLect = true;

//Get Max Registered Subject Index


OleDbCommand DBCom1 = new OleDbCommand("SELECT
MAX(RLC_INDEX) AS Expr1 FROM REG_LECT", DBCon1);
try
{

IMRegSInd = (int)DBCom1.ExecuteScalar();
DBCom1.Dispose();
}
catch (System.NullReferenceException)
{
IMRegSInd = 0;
}
catch (System.InvalidCastException)
{
IMRegSInd = 0;
}
IMRegSInd++;
}

//This method will load Class and Subject List in combobox2 and
combobox4 respectively if department name is changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BDept == true)
{
//Load List of Class in Combobox2
BClass = false;

if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use
to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
else
comboBox4.DataSource = null;
BSub = true;

//Load List of Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
BLect = true;
}
}

//This method will load Subject List in combobox4 if class name


is changed
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BClass == true)
{
//Load subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;
}
}

//This method will load Subject List in combobox4 if semester


name is changed
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSem == true)
{
//Load subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("select * from subject where dept_id =" +
comboBox1.SelectedValue.ToString() + " and class_id =" +
comboBox2.SelectedValue.ToString() + " and sem_id =" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
else
comboBox4.DataSource = null;
BSub = true;

}
}

//This method will register lecturer name to a subject


private void button1_Click(object sender, EventArgs e)
{
//Update Entry
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
//Mistake sub_ind is already available

OleDbCommand DBCom2 = new OleDbCommand("select SUB_IND


from SUBJECT where DEPT_ID=" + comboBox1.SelectedValue.ToString() + "
and CLASS_ID = " + comboBox2.SelectedValue.ToString() + " and SEM_ID="
+ comboBox3.SelectedValue.ToString() + " and SUB_IND=" +
comboBox4.SelectedValue.ToString(), DBCon1);
int ISub_Ind=0;
try
{
ISub_Ind = (int)DBCom2.ExecuteScalar();
}
catch (System.NullReferenceException)
{
ISub_Ind = 0;
}

DBCom2.Dispose();

if (ISub_Ind != 0)
{
OleDbCommand DBCom3 = new OleDbCommand("select
SUB_IND from REG_LECT where SUB_IND=" + ISub_Ind.ToString() + "and
lect_id =" + comboBox5.SelectedValue.ToString(), DBCon1);
int ITSub_ind = 0;
try
{
ITSub_ind = (int)DBCom3.ExecuteScalar();
}
catch (System.NullReferenceException)
{
ITSub_ind = 0;
}

DBCom3.Dispose();
if (ITSub_ind != 0)
{
MessageBox.Show("The Lecturer is already
Registered for this Subject");
}
else
{
OleDbCommand DBCom4 = new OleDbCommand("insert
into reg_lect values (" + IMRegSInd.ToString() + "," +
ISub_Ind.ToString() + "," + comboBox5.SelectedValue.ToString() + ")",
DBCon1);
DBCom4.ExecuteNonQuery();

DBCom4.Dispose();

//Create Subject Attendance Table


if
(int.Parse(comboBox3.SelectedValue.ToString()) % 2 != 0)
{
OleDbCommand DBCom5 = new
OleDbCommand("create table RSUBJECT" + IMRegSInd.ToString() + "
( Student_id integer, Student_name char(50), Month7LC integer, Month7LA
integer, Month8LC integer, Month8LA integer, Month9LC integer, Month9LA
integer, Month10LC integer, Month10LA integer, Month11LC integer,
Month11LA integer, Month12LC integer, Month12LA integer, TotalLC
integer, TotalLA integer, Percentage integer) ", DBCon1);
DBCom5.ExecuteNonQuery();
DBCom5.Dispose();
}
else
{
OleDbCommand DBCom6 = new
OleDbCommand("create table RSUBJECT" + IMRegSInd.ToString() + "
( Student_id integer, Student_name char(50), Month1LC integer, Month1LA
integer, Month2LC integer, Month2LA integer, Month3LC integer, Month3LA
integer, Month4LC integer, Month4LA integer, Month5LC integer, Month5LA
integer, Month6LC integer, Month6LA integer, TotalLC integer, TotalLA
integer, Percentage integer) ", DBCon1);
DBCom6.ExecuteNonQuery();
DBCom6.Dispose();
}
MessageBox.Show("Subject is now Registered");
IMRegSInd++;
}
}
else
{
MessageBox.Show("Invalid Subject");
}
}
}

private void comboBox4_SelectedIndexChanged(object sender,


EventArgs e)
{

}
}

}
Form-23

Display "Unregister Lecturer Name for a Subject" form.

Now to unregister a lecturer name click on "Unregister Lecturer


Name for a Subject" from "Lecturer Registration" as shown in
Figure. Then it displays "Unregister Lecturer Name for a
Subject". Here you have to select Department Name, Class Name,
Semester, Subject Name and Lecturer Name and then click on
"Unregister" to unregister a lecturer for the required subject
form as shown in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form23: Display "UnRegister Lecturer Name for a Subject" form
public partial class Form23 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;
bool BSem;
bool BSub;
bool BLect;

public Form23()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

~Form23()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class, Semester, registered


Subject and registered Lecturer List in combobox1, combobox2,
combobox3, combobox4 & combobox5 respectively
private void Form23_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
BDept = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load Semester List in Combobox3


BSem = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();
//set Semester Flag to True
BSem = true;

//Load List of Class in Combobox2


BClass = false;

if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id="+
comboBox1.SelectedValue.ToString()+ " and class_id= "+
comboBox2.SelectedValue.ToString()+" and sem_id="+
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;

BLect = true;
}

//This method will load Class, registered Subject and


registered Lecturer List in combobox2, combobox4 & combobox5
respectively if department name is changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BDept == true)
{
//Load List of Class in Combobox2
BClass = false;

if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use
to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);

//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
else
comboBox4.DataSource = null;

BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5

OleDbDataAdapter DBAdapter5 = new


OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);

// OleDbDataAdapter DBAdapter5 = new


OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;

BLect = true;
}
}

//This method will load registered Subject and registered


Lecturer List in combobox4 & combobox5 respectively if class name is
changed
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BClass == true)
{

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);

//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;

BLect = true;
}
}

//This method will load registered Subject and registered


Lecturer List in combobox4 & combobox5 respectively if semester name is
changed
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSem == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);

//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);

//Declare Data Set5


DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;

BLect = true;
}
}

//This method will load registered Lecturer List in combobox5


if subject name is changed
private void comboBox4_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSub == true)
{
//Load List of Registered Lecturer in Combobox2
BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;

BLect = true;
}
}

//This Method will unregister subject


private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("select
RLC_INDEX from reg_lect where Lect_ID=" +
comboBox5.SelectedValue.ToString() + " and sub_ind=" +
comboBox4.SelectedValue.ToString(), DBCon1);
int IRLC_INDEX = 0;
IRLC_INDEX = (int)DBCom1.ExecuteScalar();
DBCom1.Dispose();
//remove entery from REG_LECT
OleDbCommand DBCom2 = new OleDbCommand("Delete from
reg_lect where RLC_INDEX="+IRLC_INDEX , DBCon1);
DBCom2.ExecuteNonQuery();
DBCom2.Dispose();

//remove Table
OleDbCommand DBCom3 = new OleDbCommand("DROP TABLE
RSUBJECT" + IRLC_INDEX, DBCon1);
DBCom3.ExecuteNonQuery();
DBCom3.Dispose();

MessageBox.Show("Subject is now DeRegister");


}

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);

//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);

//Declare Data Set5


DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;

BLect = true;
}
}

}
Form-24

Display "Display List of registered subject in semester" form.

Finally to list all registered lecturers & subject in a particular


semester, Click "Display List of registered Subject in Semester"
from "Lecturer Registration" under the “Registration” menu as
shown in Figure. Then it displays "Display List of registered
Subject in Semester" form. Here you have to select Department
Name, Class Name and Semester to list registered subject name
in a semester, as shown in Figure.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form24: Display "Display List of registered subject in semester"
form
public partial class Form24 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;
bool BSem;

public Form24()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

~Form24()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department , class and semester list in


combobox1, combobox2 and combobox3 respectively.
// Also loads registered subject and lecturer list in
datagrigview1
private void Form24_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
BDept = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load Semester List in Combobox3


BSem = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();
//set Semester Flag to True
BSem = true;
//Load List of Class in Combobox2
BClass = false;

if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT SUBJECT.SUB_NAME, LECTURER.LECT_NAME FROM
((REG_LECT INNER JOIN SUBJECT ON REG_LECT.SUB_IND = SUBJECT.SUB_IND)
INNER JOIN LECTURER ON REG_LECT.LECT_ID = LECTURER.LECT_ID AND
SUBJECT.DEPT_ID = LECTURER.DEPT_ID) WHERE (SUBJECT.DEPT_ID = " +
comboBox1.SelectedValue.ToString() + ") AND (SUBJECT.CLASS_ID = " +
comboBox2.SelectedValue.ToString() + ") AND (SUBJECT.SEM_ID = " +
comboBox3.SelectedValue.ToString() + ")", DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//Fill DataGridView1
dataGridView1.DataSource = DV4;
dataGridView1.Columns[0].HeaderText = "Subject Name";
dataGridView1.Columns[1].HeaderText = "Lecturer Name";
dataGridView1.Columns[0].Width = 175;
dataGridView1.Columns[1].Width = 175;
}
}

//This method will load class list in combobox2


//Also loads registered subject and lecturer list in
datagrigview1 if Department name is changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BDept == true)
{
//Load List of Class in Combobox2
BClass = false;

if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use
to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT SUBJECT.SUB_NAME, LECTURER.LECT_NAME FROM
((REG_LECT INNER JOIN SUBJECT ON REG_LECT.SUB_IND = SUBJECT.SUB_IND)
INNER JOIN LECTURER ON REG_LECT.LECT_ID = LECTURER.LECT_ID AND
SUBJECT.DEPT_ID = LECTURER.DEPT_ID) WHERE (SUBJECT.DEPT_ID = " +
comboBox1.SelectedValue.ToString() + ") AND (SUBJECT.CLASS_ID = " +
comboBox2.SelectedValue.ToString() + ") AND (SUBJECT.SEM_ID = " +
comboBox3.SelectedValue.ToString() + ")", DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;

//Fill DataGridView1
dataGridView1.DataSource = DV4;
dataGridView1.Columns[0].HeaderText = "Subject
Name";
dataGridView1.Columns[1].HeaderText = "Lecturer
Name";
dataGridView1.Columns[0].Width = 175;
dataGridView1.Columns[1].Width = 175;
}
}
}

//This method will loads registered subject and lecturer list


in datagrigview1 if class name is changed
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BClass == true)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT SUBJECT.SUB_NAME, LECTURER.LECT_NAME FROM
((REG_LECT INNER JOIN SUBJECT ON REG_LECT.SUB_IND = SUBJECT.SUB_IND)
INNER JOIN LECTURER ON REG_LECT.LECT_ID = LECTURER.LECT_ID AND
SUBJECT.DEPT_ID = LECTURER.DEPT_ID) WHERE (SUBJECT.DEPT_ID = " +
comboBox1.SelectedValue.ToString() + ") AND (SUBJECT.CLASS_ID = " +
comboBox2.SelectedValue.ToString() + ") AND (SUBJECT.SEM_ID = " +
comboBox3.SelectedValue.ToString() + ")", DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;

//Fill DataGridView1
dataGridView1.DataSource = DV4;
dataGridView1.Columns[0].HeaderText = "Subject
Name";
dataGridView1.Columns[1].HeaderText = "Lecturer
Name";
dataGridView1.Columns[0].Width = 175;
dataGridView1.Columns[1].Width = 175;
}
}
}

//This method will loads registered subject and lecturer list


in datagrigview1 if semester name is changed
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSem == true)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT SUBJECT.SUB_NAME, LECTURER.LECT_NAME FROM
((REG_LECT INNER JOIN SUBJECT ON REG_LECT.SUB_IND = SUBJECT.SUB_IND)
INNER JOIN LECTURER ON REG_LECT.LECT_ID = LECTURER.LECT_ID AND
SUBJECT.DEPT_ID = LECTURER.DEPT_ID) WHERE (SUBJECT.DEPT_ID = " +
comboBox1.SelectedValue.ToString() + ") AND (SUBJECT.CLASS_ID = " +
comboBox2.SelectedValue.ToString() + ") AND (SUBJECT.SEM_ID = " +
comboBox3.SelectedValue.ToString() + ")", DBCon1);
//Declare Data Set4
DataSet DS4 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;

//Fill DataGridView1
dataGridView1.DataSource = DV4;
dataGridView1.Columns[0].HeaderText = "Subject
Name";
dataGridView1.Columns[1].HeaderText = "Lecturer
Name";
dataGridView1.Columns[0].Width = 175;
dataGridView1.Columns[1].Width = 175;
}

}
}
}

form-25

Step7. Register Students

Display "Register Student Name for a Subject" form.


In this step we can add or register students for a particular
subject to do so, click on "Student Registration" of
"Registration". It consist of three sub menus, namely "Register
Student Name for a subject", "Unregister Student Name for a
Subject" and ”Display List of student register for a subject”, as
shown in Figure.

If you click on ”Register Student Name for a subject", it will


display "Register Student Name for a subject" form as shown in
Figure. This form is used to register a student to subject. Here
you have to first select Department Name, Class Name,
Semester, Subject Name, and Lecturer Name. After that you can
either choose "Select All" or "Select Student by Roll No." option.
The "Select All" option is shown in Figure , this selects all
student from the selected class for that subject.

The "Select Student by Roll No." option will display one Text Box
where you have to manually enter the student roll numbers for
registration for the selected subject by the selected lecturer, as
shown in Figure.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form25: Display "Register Student Name for a Subject" form
public partial class Form25 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;
bool BSem;
bool BSub;
bool BLect;

public Form25()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

~Form25()
{
//Close DataBase Connection 1
DBCon1.Close();
}

////This method will load Department, Class, Semester, Subject


and Lecturer List in combobox1, combobox2, combobox3, combobox4 &
combobox5 respectively
private void Form25_Load(object sender, EventArgs e)
{
//Disable Student Selection by Roll Number
radioButton1.Checked = true;
richTextBox1.Visible = false;
label6.Visible = false;

//Load List of Department in Combobox1


BDept = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load Semester List in Combobox3


BSem = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();
//set Semester Flag to True
BSem = true;

//Load List of Class in Combobox2


BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true
BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;

BLect = true;

////This method will load Class, Subject and Lecturer List in


combobox2, combobox4 & combobox5 respectively if department is changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Load List of Class in Combobox2
if (BDept == true)
{
BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use
to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

//This method will load Subject and Lecturer List in combobox4


& combobox5 respectively if class name is changed
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BClass == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

//This method will load Subject and Lecturer List in combobox4


& combobox5 respectively if semester name is changed
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSem == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

}
}

//This method will load Lecturer List in combobox5


respectively if subject name is changed
private void comboBox4_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSub == true)
{
//Load List of Registered Lecturer in Combobox2
BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

private void radioButton1_CheckedChanged(object sender,


EventArgs e)
{
if (radioButton1.Checked == true)
{
richTextBox1.Visible = false;
label6.Visible = false;
}
}

private void radioButton2_CheckedChanged(object sender,


EventArgs e)
{
if (radioButton2.Checked == true)
{
richTextBox1.Visible = true;
label6.Visible = true;
}

private void richTextBox1_TextChanged(object sender, EventArgs


e)
{
int i = 0;
int count = 0;
int num = 0;
for (i = 0; i < richTextBox1.Lines.Length; i++)
{
if (string.Compare(richTextBox1.Lines[i], "") != 0)
{
try
{
num = Int32.Parse(richTextBox1.Lines[i]);
count++;
label8.Text = count.ToString();
}
catch (System.FormatException)
{
richTextBox1.Text = "";
MessageBox.Show("Pasting Non-Numeric data is
not allowed");
count = 0;
}
catch (System.OverflowException)
{

richTextBox1.Lines[i].Remove(0);
count = 0;
}

}
}
}

private void richTextBox1_KeyPress(object sender,


KeyPressEventArgs e)
{
char a = e.KeyChar;
int result;
try
{
result = Int32.Parse(a.ToString());
}
catch (System.FormatException)
{
if (e.KeyChar != '\n' || e.KeyChar != ' ')
e.KeyChar = '\0';
}
}

//This Method will register Studnet name for a subject


private void button1_Click(object sender, EventArgs e)
{
bool BReg_stu = false;
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}

if (Reg_Sub_Ind > 0)
{
if (radioButton1.Checked == true)
{
OleDbCommand DBCom2 = new OleDbCommand("select
distinct student_id, student_name from student where dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + " order by student_id asc",
DBCon1);
OleDbDataReader DBReader2;
DBReader2 = DBCom2.ExecuteReader();
DBCom2.Dispose();
if (DBReader2.HasRows)
{
while (DBReader2.Read())
{
OleDbCommand DBCom6 = new
OleDbCommand("SELECT Student_id FROM RSUBJECT" + Reg_Sub_Ind + " where
student_id =" + DBReader2.GetValue(0).ToString(), DBCon1);
int TStu_no=0;
try
{
TStu_no =
(int)DBCom6.ExecuteScalar();
DBCom6.Dispose();
}
catch(System.NullReferenceException)
{
TStu_no=0;
DBCom6.Dispose();
}
if(TStu_no==0)
{
OleDbCommand DBCom3 = new
OleDbCommand("Insert into RSUBJECT" + Reg_Sub_Ind + " values(" +
DBReader2.GetValue(0).ToString() + ",'" +
DBReader2.GetValue(1).ToString() + "',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 )",
DBCon1);
try
{
DBCom3.ExecuteNonQuery();
BReg_stu = true;
DBCom3.Dispose();
}
catch
(System.Data.OleDb.OleDbException)
{
MessageBox.Show("Student Roll
No. " + DBReader2.GetValue(0).ToString() + " already register for this
Subject");
DBCom3.Dispose();
}
}
}

}
}
else if (radioButton2.Checked == true)
{
bool BStu = true;
int i = 0;
int ICur_Stu_no = 0;

for (i = 0; i < richTextBox1.Lines.Length &&


BStu == true; i++)
{
if
(string.Compare(richTextBox1.Lines[i].ToString(), "") != 0)
{
ICur_Stu_no =
int.Parse(richTextBox1.Lines[i]);
OleDbCommand DBCom4 = new
OleDbCommand("SELECT student_id FROM STUDENT WHERE dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + "and student_id =" +
ICur_Stu_no.ToString(), DBCon1);
int ITStu_no = 0;
try
{
ITStu_no =
(int)DBCom4.ExecuteScalar();
DBCom4.Dispose();
BStu = true;
}
catch (System.NullReferenceException)
{
ITStu_no = 0;
int j = i + 1;
DBCom4.Dispose();
MessageBox.Show("Roll No: " +
ICur_Stu_no.ToString() + " entered at line " + j.ToString() + " does
not exist");
BStu = false;
}
}
}
if (BStu == true)
{
for (i = 0; i <
richTextBox1.Lines.Length; i++)
{
if
(string.Compare(richTextBox1.Lines[i].ToString(), "") != 0)
{
OleDbCommand DBCom6 = new
OleDbCommand("SELECT Student_id FROM RSUBJECT" + Reg_Sub_Ind + " where
student_id =" + richTextBox1.Lines[i].ToString(), DBCon1);
int TStu_no=0;
try
{
TStu_no =
(int)DBCom6.ExecuteScalar();
DBCom6.Dispose();
}
catch(System.NullReferenceE
xception)
{
TStu_no=0;
DBCom6.Dispose();
}
if (TStu_no == 0)
{
//
OleDbCommand DBCom7 =
new OleDbCommand("select student_name from student where dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + " and
student_id="+richTextBox1.Lines[i].ToString() , DBCon1);
OleDbDataReader
DBReader7;
DBReader7 =
DBCom7.ExecuteReader();
DBCom7.Dispose();
if(DBReader7.HasRows)
{
while(DBReader7.Rea
d())
{
OleDbCommand
DBCom5 = new OleDbCommand("Insert into RSUBJECT" + Reg_Sub_Ind + "
values(" + richTextBox1.Lines[i].ToString() + ",'" +
DBReader7.GetValue(0).ToString() + "',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)",
DBCon1);
try
{
DBCom5.Exec
uteNonQuery();
DBCom5.Disp
ose();
BReg_stu =
true;
}
catch
(System.Data.OleDb.OleDbException)
{
MessageBox.
Show("Student Roll No. " + richTextBox1.Lines[i] + " already register
for this Subject");
DBCom5.Disp
ose();
} }
} }
} }
}

else
MessageBox.Show("No Lecturer Registered for this
Subject");
{
richTextBox1.ResetText();
MessageBox.Show("Registration Completed");
}
else
MessageBox.Show("Registration Already Completed");
}
}
} }

Form-26

Display "Unregister Student Name for a Subject" form.


Similarly, to unregister a student for a subject, click "Unregister
Student Name for a Subject" option from "Student Registration"
as show in Figure & click on "Unregister Student Name for a
Subject", it will display "Unregister Student Name for a Subject"
form as shown in Figure. Here you have to first select
Department name, Class name, Semester Name, Subject Name,
Lecturer Name and then enter student roll no. If student roll no
is valid then it displays student name as shown in Figure.
Otherwise it will not display student name. If student roll no is
valid then click on "Unregister" to unregister student for that
subject.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form26: Display "UnRegister Student Name for a Subject" form
public partial class Form26 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;
bool BSem;
bool BSub;
bool BLect;
public Form26()
{
InitializeComponent();
//Intialise New DataBase Connection 1
DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

~Form26()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class, Semester, Subject


and Lecturer List in combobox1, combobox2, combobox3, combobox4 &
combobox5 respectively
private void Form26_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
BDept = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load Semester List in Combobox3


BSem = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();
//set Semester Flag to True
BSem = true;

//Load List of Class in Combobox2


BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}

//This method will load Class, Subject and Lecturer List in


combobox2, combobox4 & combobox5 respectively if department name is
changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Load List of Class in Combobox2
if (BDept == true)
{
BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use
to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

//This method will load Subject and Lecturer List in combobox4


& combobox5 respectively if class name is changed
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BClass == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

//This method will load Subject and Lecturer List in combobox4


& combobox5 respectively if semester name is changed
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSem == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

}
}

//This method will load Lecturer List in combobox5 if subject


name is changed
private void comboBox4_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSub == true)
{
//Load List of Registered Lecturer in Combobox2
BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

private void textBox1_TextChanged(object sender, EventArgs e)


{
bool a;
int i = textBox1.Text.Trim().Length;
for (int j = 0; j < i; j++)
{
a = char.IsNumber(textBox1.Text.Trim(), j);
if (a == false)
{
textBox1.Text = "";
}

}
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
if (string.Compare(textBox1.Text.ToString(), "") != 0)
{
OleDbCommand DBCom1 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}
if (Reg_Sub_Ind > 0)
{
OleDbCommand DBCom = new OleDbCommand("select
student_id from RSUBJECT"+ Reg_Sub_Ind.ToString()+ " Where
Student_id="+ textBox1.Text ,DBCon1);
int ISTu_ID=0;
try
{
ISTu_ID = (int)DBCom.ExecuteScalar();
DBCom.Dispose();
}
catch (System.NullReferenceException)
{
ISTu_ID = 0;
DBCom.Dispose();
}

if (ISTu_ID > 0)
{
OleDbCommand DBCom3 = new
OleDbCommand("select student_name from student where dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + " and student_id=" +
textBox1.Text.ToString(), DBCon1);
try
{
textBox2.Text = "";
textBox2.Text =
(string)DBCom3.ExecuteScalar();
DBCom3.Dispose();
}
catch (System.NullReferenceException)
{
textBox2.Text = "";
}
}
else
textBox2.Text = "";

}
}
else
textBox2.Text = "";
}
}

//This method will Unregister student name for subject


private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}

if (Reg_Sub_Ind > 0)
{
if (string.Compare(textBox2.Text.ToString(), "") !=
0)
{
OleDbCommand DBCom2 = new OleDbCommand("Delete
from RSUBJECT" + Reg_Sub_Ind.ToString() + " where Student_id=" +
textBox1.Text, DBCon1);
DBCom2.ExecuteNonQuery();
textBox1.Text = "";
textBox2.Text = "";
DBCom2.Dispose();
}
else
MessageBox.Show("Invalid Student Roll No.");
} } } } }
Form-27

Display "Display List of registered Student for a subject" form.

Now if you want to check the list of students from a class,


registered for a subject, then click "Display List of Student
Register for a Subject" from "Student Registration" sub menu
under “Registration” menu as shown in Figure. It will display
"Display List of Student Register for a Subject" form as shown in
Figure . Here you have to select Department Name, Class Name,
Semester Name, Subject Name, Lecturer Name to view list of
student register for that subject and lecturer.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form27: Display "Display List of registered Student for a
subject" form
public partial class Form27 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;
bool BSem;
bool BSub;
bool BLect;

public Form27()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

~Form27()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class, Semester, Subject


and Lecturer List in combobox1, combobox2, combobox3, combobox4 &
combobox5 respectively
//This method will also load Register Student list in
datagridview1
private void Form27_Load(object sender, EventArgs e)
{
//Load List of Department in Combobox1
BDept = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load Semester List in Combobox3


BSem = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();
//set Semester Flag to True
BSem = true;

//Load List of Class in Combobox2


BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;

BLect = true;
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}
if (Reg_Sub_Ind > 0)
{
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("Select Student_id, Student_name from Student where
student_id in(select student_id from RSUBJECT" + Reg_Sub_Ind + ") and
dept_id=" + comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + " order by student_id", DBCon1);
DataSet DS = new DataSet();
int i = DBAdapter2.Fill(DS, "Student");
DataTable DT = DS.Tables["Student"];
DataView DV = DT.DefaultView;
dataGridView1.DataSource = DV;
dataGridView1.Columns[0].HeaderText = "Student Roll
No.";
dataGridView1.Columns[1].HeaderText = "Student
Name";
DBAdapter2.Dispose();
}
else
dataGridView1.DataSource = null;
}
}

//This method will load Class, Subject and Lecturer List in


combobox2, combobox4 & combobox5 respectively if Department is Changed
//This method will also load Register Student list in
datagridview1
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
//Load List of Class in Combobox2
if (BDept == true)
{
BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use
to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true

BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}
if (Reg_Sub_Ind > 0)
{
OleDbDataAdapter DBAdapter1 = new
OleDbDataAdapter("Select Student_id, Student_name from Student where
student_id in(select student_id from RSUBJECT" + Reg_Sub_Ind + ") and
dept_id=" + comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + " order by student_id", DBCon1);
DataSet DS = new DataSet();
int i = DBAdapter1.Fill(DS, "Student");
DataTable DT = DS.Tables["Student"];
DataView DV = DT.DefaultView;
dataGridView1.DataSource = DV;
dataGridView1.Columns[0].HeaderText = "Student
Roll No.";
dataGridView1.Columns[1].HeaderText = "Student
Name";
DBAdapter1.Dispose();
}
}
else
dataGridView1.DataSource = null;

}
}

//This method will load Subject and Lecturer List in combobox4


& combobox5 respectively if class is Changed
//This method will also load Register Student list in
datagridview1
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BClass == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}
if (Reg_Sub_Ind > 0)
{
OleDbDataAdapter DBAdapter1 = new
OleDbDataAdapter("Select Student_id, Student_name from Student where
student_id in(select student_id from RSUBJECT" + Reg_Sub_Ind + ") and
dept_id=" + comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + " order by student_id", DBCon1);
DataSet DS = new DataSet();
int i = DBAdapter1.Fill(DS, "Student");
DataTable DT = DS.Tables["Student"];
DataView DV = DT.DefaultView;
dataGridView1.DataSource = DV;
dataGridView1.Columns[0].HeaderText = "Student
Roll No.";
dataGridView1.Columns[1].HeaderText = "Student
Name";
DBAdapter1.Dispose();
}
else
dataGridView1.DataSource = null;
}

}
}
//This method will load Subject and Lecturer List in combobox4
& combobox5 respectively if semester is Changed
//This method will also load Register Student list in
datagridview1
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSem == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}
if (Reg_Sub_Ind > 0)
{
OleDbDataAdapter DBAdapter1 = new
OleDbDataAdapter("Select Student_id, Student_name from Student where
student_id in(select student_id from RSUBJECT" + Reg_Sub_Ind + ") and
dept_id=" + comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + " order by student_id", DBCon1);
DataSet DS = new DataSet();
int i = DBAdapter1.Fill(DS, "Student");
DataTable DT = DS.Tables["Student"];
DataView DV = DT.DefaultView;
dataGridView1.DataSource = DV;
dataGridView1.Columns[0].HeaderText = "Student
Roll No.";
dataGridView1.Columns[1].HeaderText = "Student
Name";
DBAdapter1.Dispose();
}
else
dataGridView1.DataSource = null;
}

}
}

//This method will load Lecturer List in combobox5 if subject


is Changed
//This method will also load Register Student list in
datagridview1
private void comboBox4_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSub == true)
{
//Load List of Registered Lecturer in Combobox2
BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

if (comboBox1.SelectedValue != null &&


comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}
if (Reg_Sub_Ind > 0)
{
OleDbDataAdapter DBAdapter1 = new
OleDbDataAdapter("Select Student_id, Student_name from Student where
student_id in(select student_id from RSUBJECT" + Reg_Sub_Ind + ") and
dept_id=" + comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + " order by student_id", DBCon1);
DataSet DS = new DataSet();
int i = DBAdapter1.Fill(DS, "Student");
DataTable DT = DS.Tables["Student"];
DataView DV = DT.DefaultView;
dataGridView1.DataSource = DV;
dataGridView1.Columns[0].HeaderText = "Student
Roll No.";
dataGridView1.Columns[1].HeaderText = "Student
Name";
DBAdapter1.Dispose();
}
else
dataGridView1.DataSource = null;
}

}
}
//This method will load Register Student list in datagridview1
private void comboBox5_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BLect == true)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null)
{
OleDbCommand DBCom1 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom1.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}
if (Reg_Sub_Ind > 0)
{
OleDbDataAdapter DBAdapter1 = new
OleDbDataAdapter("Select Student_id, Student_name from Student where
student_id in(select student_id from RSUBJECT" + Reg_Sub_Ind + ") and
dept_id=" + comboBox1.SelectedValue.ToString() + " and class_id=" +
comboBox2.SelectedValue.ToString() + " order by student_id", DBCon1);
DataSet DS = new DataSet();
int i = DBAdapter1.Fill(DS, "Student");
DataTable DT = DS.Tables["Student"];
DataView DV = DT.DefaultView;
dataGridView1.DataSource = DV;
dataGridView1.Columns[0].HeaderText = "Student
Roll No.";
dataGridView1.Columns[1].HeaderText = "Student
Name";
DBAdapter1.Dispose();
}
else
dataGridView1.DataSource = null;
}
}
}
}

}
Form28

Step8. Add attendance of Students for registered subject.

Display "Add Attendance (Subject wise)" form.


Then "Add Attendance Subject wise" form will be displayed as
shown in Figure. Here you have to first select Department Name,
Class Name, Semester, Subject Name, Lecturer Name and Month
then click on "Show Attendance Sheet". It will display
attendance sheet for Department, Class, Semester, Subject,
Lecturer, and Month you selected. Then first enter No. of
Lectures Conducted and then you can add number of lectures
attended by the students in month column. For e.g. in Figure
"July" column of attendance sheet indicates attendance for the
month of July. Once you add all attendance of students, click on
"Add attendance”. It will save attendance for month of July in
the database. Similarly we can follow this step to add the
attendance for the remaining months.
Note: The attendance count that is entered into the column
should be less than or equal to the number entered in the “No. of
Lectures Conducted”.

If the attendance count entered is greater than the “No. of


Lectures Conducted” than the corresponding cell is highlighted
with “yellow” color, which denotes that the entry in that cell is
invalid/inconsistent.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Attendance
{
//Form28: Display "Add Attendance (Subjectwise)" form
public partial class Form28 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;
bool BSem;
bool BSub;
bool BLect;
bool BMonth;
bool BIsGridDisplay;

public Form28()
{
InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

~Form28()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class, Semester, Subject


and Lecturer List in combobox1, combobox2, combobox3, combobox4 &
combobox5 respectively
private void Form28_Load(object sender, EventArgs e)
{
BIsGridDisplay = false;
//Load List of Department in Combobox1
BDept = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load Semester List in Combobox3


BSem = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();
//set Semester Flag to True
BSem = true;

//Load List of Class in Combobox2


BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true
BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

///////////////////////////////////////////////////////////
/
BMonth = false;

string SMonth;
if (comboBox3.SelectedValue != null)
{
//Get DataBase Adapter6
if(int.Parse(comboBox3.SelectedValue.ToString())%2==0)
{
SMonth="select * from amonth where month_id between
1 and 6";
}
else
{
SMonth = "select * from amonth where month_id
between 7 and 12";
}
OleDbDataAdapter DBAdapter6 = new
OleDbDataAdapter(SMonth, DBCon1);
//Declare Data Set6
DataSet DS6 = new DataSet();
//Intialise IRecordCount6 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount6 = 0;
//Fill DataBase Adapter6 and set IRecordCount6
IRecordCount6 = DBAdapter6.Fill(DS6, "DMonth");
//Set Data Table6
DataTable DT6 = DS6.Tables["DMonth"];
//Set Data View6
DataView DV6 = DT6.DefaultView;
//set Combobox Data source to Data View 6
comboBox6.DataSource = DV6;
//Set DisplayMember and ValueMember of Combobox6
comboBox6.DisplayMember = "MONTH_NAME";
comboBox6.ValueMember = "MONTH_ID";
//Dispose DataTable6, DataSet6, DataBase Adapter6
DT6.Dispose();
DS6.Dispose();
DBAdapter6.Dispose();
}
else
comboBox6.DataSource = null;

BMonth = true;
///////////////////////////////////////////////////////////
/

//This method will load Class, Semester, Subject and Lecturer


List in combobox1, combobox2, combobox3, combobox4 & combobox5
respectively
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BDept == true)
{
//Load List of Class in Combobox2
BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use
to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true
BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

//This method will load Subject and Lecturer List in combobox4


& combobox5 respectively if Class Name is Changed
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BClass == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

//This method will load Subject and Lecturer List in combobox4


& combobox5 respectively if semester is changed
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSem == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

///////////////////////////////////////////////////////
/////
BMonth = false;

string SMonth;
if (comboBox3.SelectedValue != null)
{
//Get DataBase Adapter6
if (int.Parse(comboBox3.SelectedValue.ToString()) %
2 == 0)
{
SMonth = "select * from amonth where month_id
between 1 and 6";
}
else
{
SMonth = "select * from amonth where month_id
between 7 and 12";
}

OleDbDataAdapter DBAdapter6 = new


OleDbDataAdapter(SMonth, DBCon1);
//Declare Data Set6
DataSet DS6 = new DataSet();
//Intialise IRecordCount6 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount6 = 0;
//Fill DataBase Adapter6 and set IRecordCount6
IRecordCount6 = DBAdapter6.Fill(DS6, "DMonth");
//Set Data Table6
DataTable DT6 = DS6.Tables["DMonth"];
//Set Data View6
DataView DV6 = DT6.DefaultView;
//set Combobox Data source to Data View 6
comboBox6.DataSource = DV6;
//Set DisplayMember and ValueMember of Combobox6
comboBox6.DisplayMember = "MONTH_NAME";
comboBox6.ValueMember = "MONTH_ID";
//Dispose DataTable6, DataSet6, DataBase Adapter6
DT6.Dispose();
DS6.Dispose();
DBAdapter6.Dispose();
}
else
comboBox6.DataSource = null;

BMonth = true;
}
}

//This method will load Lecturer List in combobox5 respectively


if subject is changed
private void comboBox4_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSub == true)
{
//Load List of Registered Lecturer in Combobox2
BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

}
}

//This method will show attendance sheet in datagridview1


private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null &&
comboBox6.SelectedValue != null)
{
OleDbCommand DBCom8 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom8.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}

if (Reg_Sub_Ind > 0)
{
OleDbDataAdapter DBAdapter7 = new
OleDbDataAdapter("Select student_id, student_name, month" +
comboBox6.SelectedValue.ToString() + "la from RSUBJECT" +
Reg_Sub_Ind.ToString() + " order by student_id", DBCon1);
DataSet DS7 = new DataSet();
int i7 = DBAdapter7.Fill(DS7, "Student");
DataTable DT7 = DS7.Tables["Student"];
DataView DV7 = DT7.DefaultView;
dataGridView1.DataSource = DV7;
dataGridView1.Columns[0].HeaderText = "Student
Roll No.";
dataGridView1.Columns[1].HeaderText = "Student
Name";
dataGridView1.Columns[0].ReadOnly = true;
dataGridView1.Columns[1].ReadOnly = true;
dataGridView1.Columns[0].Width = 125;
dataGridView1.Columns[1].Width = 300;

DBAdapter7.Dispose();
DS7.Dispose();
DT7.Dispose();

OleDbCommand DBCom = new OleDbCommand("select


Month_name from amonth where month_id= " +
comboBox6.SelectedValue.ToString(), DBCon1);
dataGridView1.Columns[2].HeaderText =
(string)DBCom.ExecuteScalar();
DBCom.Dispose();
BIsGridDisplay = true;
}
}
}

//This method will add attendance in database


private void button2_Click(object sender, EventArgs e)
{
bool BDataGrid = true;
int IMonthLC = 0;
try
{
IMonthLC =
int.Parse(maskedTextBox1.Text.Trim().ToString());
}
catch (System.FormatException)
{
IMonthLC = 0;
if(BDataGrid==true)
BDataGrid = false;
}
int IDGRows = 0;

for (IDGRows = 0; IDGRows < dataGridView1.RowCount/*&&


BDataGrid == true*/; IDGRows++)
{
int IDGMLA = 0;

try
{
IDGMLA =
int.Parse(dataGridView1.Rows[IDGRows].Cells[2].Value.ToString());

}
catch (System.FormatException)
{
IDGMLA = 0;
dataGridView1.Rows[IDGRows].Cells[2].Value = 0;
if (BDataGrid == true)
BDataGrid = false;
}

if (IDGMLA > IMonthLC)


{
dataGridView1.Rows[IDGRows].Cells[2].Style.BackColo
r = Color.Yellow;

if (BDataGrid == true)
BDataGrid = false;
}
else
{
dataGridView1.Rows[IDGRows].Cells[2].Style.BackColo
r = Color.White;
}
}
if (BDataGrid == false)
MessageBox.Show("Invalid Entry");

if (BIsGridDisplay == true && BDataGrid ==true)


{

OleDbCommand DBCom8 = new OleDbCommand("select rlc_index


from reg_lect where sub_ind=" + comboBox4.SelectedValue.ToString() + "
and lect_id =" + comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom8.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}
if (Reg_Sub_Ind > 0)
{
int IRow = 0;
for (IRow = 0; IRow < dataGridView1.RowCount; IRow+
+)
{
string s1 = "Update RSUBJECT" +
Reg_Sub_Ind.ToString() + " set Month" +
comboBox6.SelectedValue.ToString() + "LC =" +
maskedTextBox1.Text.ToString() + ", Month" +
comboBox6.SelectedValue.ToString() + "LA =" +
dataGridView1.Rows[IRow].Cells[2].Value.ToString() + " where
student_id=" + dataGridView1.Rows[IRow].Cells[0].Value.ToString();
OleDbCommand DBCom9 = new OleDbCommand(s1,
DBCon1);
DBCom9.ExecuteNonQuery();
DBCom9.Dispose();
}

string s2, s3;


if (int.Parse(comboBox3.SelectedValue.ToString()) %
2 == 0)
{
s2 = "Totallc=
Month1LC+Month2LC+Month3LC+Month4LC+Month5LC+Month6LC";
s3 = "Totalla=
Month1LA+Month2LA+Month3LA+Month4LA+Month5LA+Month6LA";
}
else
{
s2 = "Totallc=
Month7LC+Month8LC+Month9LC+Month10LC+Month11LC+Month12LC";
s3 = "Totalla=
Month7LA+Month8LA+Month9LA+Month10LA+Month11LA+Month12LA";
}
string s4 = " Percentage =TotalLA/TotalLC *100 ";

OleDbCommand DBCom10 = new OleDbCommand("update


RSUBJECT" + Reg_Sub_Ind.ToString() + " set " + s2, DBCon1);
DBCom10.ExecuteNonQuery();
DBCom10.Dispose();

OleDbCommand DBCom11 = new OleDbCommand("update


RSUBJECT" + Reg_Sub_Ind.ToString() + " set " + s3, DBCon1);
DBCom11.ExecuteNonQuery();
DBCom11.Dispose();
try
{
OleDbCommand DBCom12 = new OleDbCommand("update
RSUBJECT" + Reg_Sub_Ind.ToString() + " set " + s4, DBCon1);
DBCom12.ExecuteNonQuery();
DBCom12.Dispose();
}
catch (System.Data.OleDb.OleDbException)
{
}
MessageBox.Show("Completed");

}
}

private void comboBox5_SelectedIndexChanged(object sender,


EventArgs e)
{

private void comboBox6_SelectedIndexChanged(object sender,


EventArgs e)
{

Form-29
Display "Build Attendance Document (subject wise)" form.

Then "Build attendance Document (Subject wise)" form will be


displayed as shown in Figure 9.2. Here you have to first select
Department Name, Class Name, Semester, Subject Name and
Lecturer Name then click on "Show Attendance". It will display
attendance sheet at the middle of screen as show in Figure.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using Word = Microsoft.Office.Interop.Word;
using System.Reflection;

namespace Attendance
{
//Form29: Display "Build Attendance Document (subject wise)" form
public partial class Form29 : Form
{
OleDbConnection DBCon1;
bool BDept;
bool BClass;
bool BSem;
bool BSub;
bool BLect;

bool BIsGridDisplay;

public Form29()
{

InitializeComponent();

//Intialise New DataBase Connection 1


DBCon1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=MonthlyReport.mdb");

//Open DataBase Connection 1


DBCon1.Open();
}

~Form29()
{
//Close DataBase Connection 1
DBCon1.Close();
}

//This method will load Department, Class, Semester, Subject


and Lecturer List in combobox1, combobox2, combobox3, combobox4 &
combobox5 respectively
private void Form29_Load(object sender, EventArgs e)
{
BIsGridDisplay = false;
//Load List of Department in Combobox1
BDept = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter1 = new OleDbDataAdapter("select
* from department", DBCon1);
//Declare Data Set1
DataSet DS1 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to store
no. of record afected
int IRecordCount = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount = DBAdapter1.Fill(DS1, "Department");
//Set Data Table1
DataTable DT1 = DS1.Tables["Department"];
//Set Data View1
DataView DV1 = DT1.DefaultView;
//set Combobox Data source to Data View 1
comboBox1.DataSource = DV1;
//Set DisplayMember and ValueMember of Combobox1
comboBox1.DisplayMember = "DEPT_NAME";
comboBox1.ValueMember = "DEPT_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT1.Dispose();
DS1.Dispose();
DBAdapter1.Dispose();

//Set Department Flag to true


BDept = true;

//Load Semester List in Combobox3


BSem = false;
//Get DataBase Adapter
OleDbDataAdapter DBAdapter3 = new OleDbDataAdapter("select
* from Semester", DBCon1);
//Declare Data Set3
DataSet DS3 = new DataSet();
//Intialise IRecordCount3 to 0; IRecordCount3 is use to
store no. of record afected
int IRecordCount3 = 0;
//Fill DataBase Adapter3 and set IRecordCount3
IRecordCount3 = DBAdapter3.Fill(DS3, "Semester");
//Set Data Table3
DataTable DT3 = DS3.Tables["Semester"];
//Set Data View3
DataView DV3 = DT3.DefaultView;
//set Combobox Data source to Data View 3
comboBox3.DataSource = DV3;
//Set DisplayMember and ValueMember of Combobox3
comboBox3.DisplayMember = "SEM_NAME";
comboBox3.ValueMember = "SEM_ID";
//Dispose DataTable3, DataSet3, DataBase Adapter3
DT3.Dispose();
DS3.Dispose();
DBAdapter3.Dispose();
//set Semester Flag to True
BSem = true;

//Load List of Class in Combobox2


BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use to
store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true
BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is use to
store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use to
store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}

//This method will load Class, Semester, Subject and Lecturer


List in combobox2, combobox3, combobox4 & combobox5 respectively if
department is changed
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BDept == true)
{
//Load List of Class in Combobox2
BClass = false;
if (comboBox1.SelectedValue != null)
{
//Get DataBase Adapter2
OleDbDataAdapter DBAdapter2 = new
OleDbDataAdapter("select * from Class where dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set2
DataSet DS2 = new DataSet();
//Intialise IRecordCount to 0; IRecordCount is use
to store no. of record afected
int IRecordCount2 = 0;
//Fill DataBase Adapter1 and set IRecordCount
IRecordCount2 = DBAdapter2.Fill(DS2, "Class");
//Set Data Table1
DataTable DT2 = DS2.Tables["Class"];
//Set Data View1
DataView DV2 = DT2.DefaultView;
//set Combobox Data source to Data View 1
comboBox2.DataSource = DV2;
//Set DisplayMember and ValueMember of Combobox1
comboBox2.DisplayMember = "CLASS_NAME";
comboBox2.ValueMember = "CLASS_ID";
//Dispose DataTable1, DataSet1, DataBase Adapter 1
DT2.Dispose();
DS2.Dispose();
DBAdapter2.Dispose();
}
//set BClass to true
BClass = true;

//Load Registerd subject List in Combobox4


BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

//This method will load Semester, Subject and Lecturer List in


combobox3, combobox4 & combobox5 respectively if Class is changed
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BClass == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

//This method will load Subject and Lecturer List in combobox4


& combobox5 respectively if Semester is changed
private void comboBox3_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSem == true)
{
//Load Registerd subject List in Combobox4
BSub = false;
//Get DataBase Adapter4
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null)
{
OleDbDataAdapter DBAdapter4 = new
OleDbDataAdapter("SELECT sub_ind, sub_name from subject where sub_ind
in(select sub_ind from reg_lect) and Dept_id=" +
comboBox1.SelectedValue.ToString() + " and class_id= " +
comboBox2.SelectedValue.ToString() + " and sem_id=" +
comboBox3.SelectedValue.ToString(), DBCon1);
//Declare Data Set4

DataSet DS4 = new DataSet();


//Intialise IRecordCount3 to 0; IRecordCount4 is
use to store no. of record afected
int IRecordCount4 = 0;
//Fill DataBase Adapter3 and set IRecordCount4
IRecordCount4 = DBAdapter4.Fill(DS4, "Subject");
//Set Data Table4
DataTable DT4 = DS4.Tables["Subject"];
//Set Data View4
DataView DV4 = DT4.DefaultView;
//set Combobox Data source to Data View 4
comboBox4.DataSource = DV4;
//Set DisplayMember and ValueMember of Combobox4
comboBox4.DisplayMember = "SUB_NAME";
comboBox4.ValueMember = "SUB_IND";
//Dispose DataTable4, DataSet4, DataBase Adapter4
DT4.Dispose();
DS4.Dispose();
DBAdapter4.Dispose();
}
BSub = true;

//Load List of Registered Lecturer in Combobox2


BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;
}
}

//This method will load Lecturer List in combobox5 respectively


if subject is changed
private void comboBox4_SelectedIndexChanged(object sender,
EventArgs e)
{
if (BSub == true)
{
//Load List of Registered Lecturer in Combobox2
BLect = false;
if (comboBox1.SelectedValue != null &&
comboBox4.SelectedValue != null)
{
//Get DataBase Adapter5
OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from lecturer where lect_id in (SELECT
Lect_id from reg_lect where sub_ind in(select sub_ind from subject
where Sub_ind =" + comboBox4.SelectedValue.ToString() + "and Dept_id="
+ comboBox1.SelectedValue.ToString() + "and class_id=" +
comboBox2.SelectedValue.ToString() + "and sem_id=" +
comboBox3.SelectedValue.ToString() + ") ) and Dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
// OleDbDataAdapter DBAdapter5 = new
OleDbDataAdapter("select * from Lecturer where lect_id in (select
lect_id from reg_lect ) and dept_id =" +
comboBox1.SelectedValue.ToString(), DBCon1);
//Declare Data Set5
DataSet DS5 = new DataSet();
//Intialise IRecordCount5 to 0; IRecordCount is use
to store no. of record afected
int IRecordCount5 = 0;
//Fill DataBase Adapter5 and set IRecordCount5
IRecordCount5 = DBAdapter5.Fill(DS5, "Lecturer");
//Set Data Table5
DataTable DT5 = DS5.Tables["Lecturer"];
//Set Data View1
DataView DV5 = DT5.DefaultView;
//set Combobox Data source to Data View 5
comboBox5.DataSource = DV5;
//Set DisplayMember and ValueMember of Combobox5
comboBox5.DisplayMember = "LECT_NAME";
comboBox5.ValueMember = "LECT_ID";
//Dispose DataTable5, DataSet5, DataBase Adapter5
DT5.Dispose();
DS5.Dispose();
DBAdapter5.Dispose();
}
else
comboBox5.DataSource = null;
BLect = true;

}
}

//This method will display Attendance Sheet


private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null &&
comboBox2.SelectedValue != null && comboBox3.SelectedValue != null &&
comboBox4.SelectedValue != null && comboBox5.SelectedValue != null )
{
OleDbCommand DBCom8 = new OleDbCommand("select
rlc_index from reg_lect where sub_ind=" +
comboBox4.SelectedValue.ToString() + " and lect_id =" +
comboBox5.SelectedValue.ToString(), DBCon1);
int Reg_Sub_Ind = 0;
try
{
Reg_Sub_Ind = (int)DBCom8.ExecuteScalar();
}
catch (System.NullReferenceException)
{
Reg_Sub_Ind = 0;
}

if (Reg_Sub_Ind > 0)
{
string s;
bool BMonth = false;
if (int.Parse(comboBox3.SelectedValue.ToString()) %
2 == 0)
{
s = "Select student_id, student_name,
Month1LA,Month2LA,Month3LA,Month4LA,Month5LA,Month6LA,
Totallc,Totalla,Percentage from RSUBJECT" + Reg_Sub_Ind.ToString() + "
order by student_id";
BMonth = false;
}
else
{
s = "Select student_id, student_name,
Month7LA,Month8LA,Month9LA,Month10LA,Month11LA,Month12LA,
Totallc,Totalla,Percentage from RSUBJECT" + Reg_Sub_Ind.ToString() + "
order by student_id";
BMonth = true;
}
OleDbDataAdapter DBAdapter7 = new
OleDbDataAdapter(s, DBCon1);
DataSet DS7 = new DataSet();
int i7 = DBAdapter7.Fill(DS7, "Student");
DataTable DT7 = DS7.Tables["Student"];
DataView DV7 = DT7.DefaultView;
dataGridView1.DataSource = DV7;
dataGridView1.Columns[0].HeaderText = "Student Roll
No.";
dataGridView1.Columns[1].HeaderText = "Student
Name";
dataGridView1.Columns[0].ReadOnly = true;
dataGridView1.Columns[1].ReadOnly = true;

dataGridView1.Columns[0].Width = 50;
dataGridView1.Columns[1].Width = 150;
dataGridView1.Columns[2].Width = 75;
dataGridView1.Columns[3].Width = 75;
dataGridView1.Columns[4].Width = 75;
dataGridView1.Columns[5].Width = 75;
dataGridView1.Columns[6].Width = 75;
dataGridView1.Columns[7].Width = 75;
dataGridView1.Columns[8].Width = 75;
dataGridView1.Columns[9].Width = 75;
dataGridView1.Columns[10].Width = 75;

if (BMonth == true)
{
dataGridView1.Columns[2].HeaderText = "July";
dataGridView1.Columns[3].HeaderText = "August";
dataGridView1.Columns[4].HeaderText =
"September";
dataGridView1.Columns[5].HeaderText =
"October";
dataGridView1.Columns[6].HeaderText =
"November";
dataGridView1.Columns[7].HeaderText =
"December";
}
else
{
dataGridView1.Columns[2].HeaderText =
"January";
dataGridView1.Columns[3].HeaderText =
"February";
dataGridView1.Columns[4].HeaderText = "March";
dataGridView1.Columns[5].HeaderText = "April";
dataGridView1.Columns[6].HeaderText = "May";
dataGridView1.Columns[7].HeaderText = "June";
}

dataGridView1.Columns[8].HeaderText = "Total
Lectures Conducted";
dataGridView1.Columns[9].HeaderText = "Total
Lectures Attended";
DBAdapter7.Dispose();
DS7.Dispose();
DT7.Dispose();
BIsGridDisplay = true;
}
else
BIsGridDisplay = false;
}
}

//This method will build word based attenance document


private void button2_Click(object sender, EventArgs e)
{

if (BIsGridDisplay == true)
{
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; // endofdoc is a
predefined bookmark

//Start Word and create a new document.


Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);

oDoc.PageSetup.PaperSize =
Word.WdPaperSize.wdPaperLegal;
oDoc.PageSetup.Orientation =
Word.WdOrientation.wdOrientLandscape;

//Insert a paragraph at the beginning of the document.


Word.Paragraph oPara1;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = "Vijay Mukhi's Computer Institute";
oPara1.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.Range.Font.Bold = 1;
oPara1.Format.SpaceAfter = 24; //24 pt spacing after
paragraph.
oPara1.Range.InsertParagraphAfter();

//Insert a paragraph at the end of the document.


Word.Paragraph oPara2;
object oRng = oDoc.Bookmarks.get_Item(ref
oEndOfDoc).Range;
oPara2 = oDoc.Content.Paragraphs.Add(ref oRng);

oPara2.Range.Text = "Department Name: " +


comboBox1.Text.ToString() + " Class Name: " +
comboBox2.Text.ToString() + " Semester: " +
comboBox3.SelectedValue.ToString() + " Subject Name: " +
comboBox4.Text.ToString();

oPara2.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara2.Format.SpaceAfter = 6;
oPara2.Range.InsertParagraphAfter();
//Insert another paragraph.
Word.Paragraph oPara3;
oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);
oPara3.Range.Text = "Lecturer Name: " +
comboBox5.Text.ToString();
oPara3.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara3.Format.SpaceAfter = 24;
oPara3.Range.InsertParagraphAfter();

//Insert a attendance sheet


//bold and italic.
Word.Table oTable;
Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref
oEndOfDoc).Range;
oTable = oDoc.Tables.Add(wrdRng,
dataGridView1.RowCount+1, dataGridView1.ColumnCount, ref oMissing, ref
oMissing);

object Ot;
Ot = Word.WdTableFormat.wdTableFormatGrid1;

oTable.AutoFormat(ref Ot, ref oMissing, ref oMissing,


ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
oTable.Range.ParagraphFormat.SpaceAfter = 6;

oTable.Cell(1, 1).Range.Text =
dataGridView1.Columns[0].HeaderText.ToString();
oTable.Cell(1, 2).Range.Text =
dataGridView1.Columns[1].HeaderText.ToString();
oTable.Cell(1, 3).Range.Text =
dataGridView1.Columns[2].HeaderText.ToString();
oTable.Cell(1, 4).Range.Text =
dataGridView1.Columns[3].HeaderText.ToString();
oTable.Cell(1, 5).Range.Text =
dataGridView1.Columns[4].HeaderText.ToString();
oTable.Cell(1, 6).Range.Text =
dataGridView1.Columns[5].HeaderText.ToString();
oTable.Cell(1, 7).Range.Text =
dataGridView1.Columns[6].HeaderText.ToString();
oTable.Cell(1, 8).Range.Text =
dataGridView1.Columns[7].HeaderText.ToString();
oTable.Cell(1, 9).Range.Text =
dataGridView1.Columns[8].HeaderText.ToString();
oTable.Cell(1, 10).Range.Text =
dataGridView1.Columns[9].HeaderText.ToString();
oTable.Cell(1, 11).Range.Text =
dataGridView1.Columns[10].HeaderText.ToString();

int r, c;
string strText;
for (r = 0; r < dataGridView1.RowCount; r++)
for (c = 0; c < 11; c++)
{
strText =
dataGridView1.Rows[r].Cells[c].Value.ToString();
oTable.Cell(r + 2, c + 1).Range.Text = strText;
}

oTable.Rows[1].Range.Font.Bold = 1;
oTable.Rows[1].Range.Font.Italic = 1;
}
else
{
MessageBox.Show("Please Show attendance first");
}
}
}}

REFERENCES

1. BOOKS NAME

• The complete guide to C# programming


• C# Dot Net

2. Websites used:

• www.google .com
• www.wikipedia.org

Vous aimerez peut-être aussi