Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Object Oriented Programming, Assignments of Object Oriented Programming

Object Oriented Programming Final Assignment

Typology: Assignments

2017/2018

Uploaded on 04/29/2023

manish_mahaseth
manish_mahaseth 🇳🇵

9 documents

Partial preview of the text

Download Object Oriented Programming and more Assignments Object Oriented Programming in PDF only on Docsity! Object Oriented Programming Niraj Yadav 1/14/18 OOP OBJECT ORIENTED PROGRAMMING P a g e 1 | 145 Table of Contents Task 1 ............................................................................................................................................. 5 I. Discuss the principles, characteristics and features of objected oriented programming. [1.1, M1] ......................................................................................................................................... 5 Object Oriented Programming .................................................................................................... 6 Class ............................................................................................................................................... 6 Objects ........................................................................................................................................... 6 Data Abstraction ........................................................................................................................... 6 Encapsulation ................................................................................................................................ 9 Constructer .................................................................................................................................. 10 Destructor .................................................................................................................................... 12 Static Members............................................................................................................................ 12 Inheritance ................................................................................................................................... 14 Inheritance: Base and Derived Classes .............................................................................................. 14 Initializing Base Class ...................................................................................................................... 14 Types of Inheritance ................................................................................................................... 15 Single Inheritance ....................................................................................................................... 15 Multiple Inheritance ........................................................................................................................ 17 Multilevel Inheritance ................................................................................................................ 20 Hierarchical Inheritance ............................................................................................................ 21 Hybrid Inheritance ..................................................................................................................... 21 Polymorphism ............................................................................................................................. 21 Static Polymorphism ....................................................................................................................... 21 Function Overloading ...................................................................................................................... 22 Operator Overloading ................................................................................................................ 22 Dynamic Polymorphism .................................................................................................................. 22 Abstract Classes .......................................................................................................................... 23 Virtual Functions ........................................................................................................................ 23 Task 2 ........................................................................................................................................... 24 I. Identify the objects and data and file structures required to implement a given design based on above scenario. [2.1] .................................................................................................... 24 OBJECT ORIENTED PROGRAMMING P a g e 4 | 145 Documentation for Design and Development of Employee Information System. .............. 130 Abstract ...................................................................................................................................... 130 Introduction: ............................................................................................................................. 131 Modules:..................................................................................................................................... 131 Overall System Design .............................................................................................................. 131 Database Design ........................................................................................................................ 132 Data Dictionary of Database Employee Information System ............................................... 133 Implementation Architecture .................................................................................................. 134 Software Functionality testing ................................................................................................. 134 Test case 2: Functionality Testing against Requirements ..................................................... 135 1. Testing the Role base User Authentication ..................................................................... 135 2. Testing of Insert, Update, Delete and Retrieval of data in Role Management Section 137 3. Testing of Insert, Update, Delete and Retrieval of data in Department Management Section. ....................................................................................................................................... 141 4. Testing of Insert, Update, Delete and Retrieval of data in Employee Management Section ........................................................................................................................................ 142 5. Testing of Search functionality of Employee Section ..................................................... 143 Conclusion ................................................................................................................................. 143 Reference: .................................................................................................................................. 144 OBJECT ORIENTED PROGRAMMING P a g e 5 | 145 Task 1 I. Discuss the principles, characteristics and features of objected oriented programming. [1.1, M1] Consider: You need to discuss the concept of Object Oriented Programming including Class and Objects, Encapsulation, Constructor, Static Members, Inheritance and Polymorphism with suitable programming example. The program must be done in C# Visual Studio 201X and you must provide the screenshots of the output of such program along with source code. In order to achieve M1, your writing need to demonstrate that an effective approach to study and research has been applied to when discussing the principles, characteristics and features of object oriented programming and assignment has submitted within agreed deadline. OBJECT ORIENTED PROGRAMMING P a g e 6 | 145 Object Oriented Programming Object-oriented programming (OOP) is the most recent concept in computer programming approach. OOP allows decomposition of program into a number of entities called objects and then builds data and functions around these objects. However, the function of one object can access the functions of another object. As the OOP is the modern programming language it has some principal and characteristics which are discussed below: Class Object is the basic element of OOP approach which is declared by using class. Class is a collection of objects of similar type. For example, mango, apple and orange are the members of the class fruits. Classes are user defined data types and behave like the built in data types of the programming languages. Classes are also known as abstract data types (ADT) in OOP because they use the concept of data abstraction. Objects Object is the basic run time entities in an object oriented program which consists of data and functions. It may also represent user defined data. Programming problem is analyzed in terms of objects. The program objects are similar to the real world objects. Hence, object is a variable consisting both routine and data that is treated as discrete entity within programming. Data Abstraction Data Abstraction is the lessening of a specific assortment of information to a rearranged representation of the entirety. Abstraction, by and large, is the procedure of taking without end or expelling qualities from something keeping in mind the end goal to diminish it to an arrangement of crucial attributes. OBJECT ORIENTED PROGRAMMING P a g e 9 | 145 Encapsulation Encapsulation is striking part features of OOP approach. The wrapping up of data and function into a single unit called class is known as encapsulation. The data is not accessible to the outside world and only those functions which are wrapped in the class can access the data. This feature of OOP approach prevents the data from the accidental or unnecessary modifications. The functions of the object provide the interface between the object data and program. The code that defines encapsulation is shown below: OBJECT ORIENTED PROGRAMMING P a g e 10 | 145 Constructer A "constructor" is an extraordinary part work whose endeavor is to actually present of an object of its class. It is excellent in light of the fact that its name is the same name of the same as the class name. It is called constructor since it fabricates the assessed estimations of the information individuals from the class. Rules to write constructer are given below: • Constructor proclaimed with no arrival sort. • It ought to have open or ensured access inside the class. • They are summoned naturally when the articles are made. • They can't be acquired; however a determined class can call the base constructors. • Constructors can't be virtual, can't allude to their locations. • An item with a constructor (or destructor) can't be utilized as an individual from a union. OBJECT ORIENTED PROGRAMMING P a g e 11 | 145 OBJECT ORIENTED PROGRAMMING P a g e 14 | 145 Inheritance Inheritance is the process by which objects of one class acquires the similar properties of objects of another class from which they are derived. In OOP, the concept of inheritance provides the idea of reusability. This means that we can additional features to an existing class without modifying it. Inheritance: Base and Derived Classes The current class from which another class is inferred is known as base class and the new made is derived class. A base class might be an immediate base class of an inferred class, or an aberrant base class of a determined class. An immediate base class of an inferred class is unequivocally recorded in that determined class' header with the colon (:) documentation when derived class is announced. An aberrant base class is not unequivocally recorded in the determined class' header; rather the backhanded base class is acquired from two or more step up the class chain of importance. There are many types of inheritance which are discussed below: Initializing Base Class The derived class inherits the base class member variables and member methods. Therefore the super class object should be created before the subclass is created. You can give instructions for superclass initialization in the member initialization list. OBJECT ORIENTED PROGRAMMING P a g e 15 | 145 Types of Inheritance Single Inheritance Single Inheritance a typical type of inheritance, in which classes have one base class. The base class from which every class is inferred is pronounced before the presentation of the determined class. It is not adequate to give a forward-referencing statement to a base class; it must be a finished revelation. The program and Output is given below: OBJECT ORIENTED PROGRAMMING P a g e 16 | 145 OBJECT ORIENTED PROGRAMMING P a g e 19 | 145 OBJECT ORIENTED PROGRAMMING P a g e 20 | 145 Multilevel Inheritance In this type of inheritance, a class is obtained from another translated class. Thusly, base class of a translated class is in like way chosen of another base class. Output and the program is shown below: OBJECT ORIENTED PROGRAMMING P a g e 21 | 145 Hierarchical Inheritance At the point when a class has more than one child classes (sub classes) or in another form, more than one young class has similar guardian class then such sort of inheritance is known as hierarchical inheritance. Hybrid Inheritance It is the combination of Hierarchical and Multilevel Inheritance. Hybrid inheritances is also known as virtual inheritance. It is used to declare to share the member data instincts with other instincts of same base. Polymorphism Polymorphism in article arranged programming insinuates written work projects tongue's ability to process dissents differently depending upon their data sort or class. More especially, it is the ability to re-imagined procedures for inferred classes. Polymorphism is of two types i.e. “static polymorphism” and “dynamic polymorphism”. In static polymorphism, the reply of function is set on at the compile time and in dynamic polymorphism, is marked at run-time. Static Polymorphism The method of connecting the function on at the compile time. They are like wisely called static binding. Csharp gives two methods to work on static polymorphism. They are: • Function overloading OBJECT ORIENTED PROGRAMMING P a g e 24 | 145 Task 2 I. Identify the objects and data and file structures required to implement a given design based on above scenario. [2.1] Consider: Your writing needs to identify Programming Language (Visual C++, Visual Basic.Net, C#. Net etc), Programming Platform (GUI, CLI, Scripted etc), Delivery Environment (Desktop, web based, mobile etc) and Development Environment (Visual studio .net, Visual C++ compiler etc), and Then identify Data members, Methods and Objects based on scenario required for the class data and file structure. Scenario According to the scenario given I’m requested to make new Employee Information System of Cloud Infosys pvt.ltd which is located to other major city like Pokhara, Biratnagar, Birgunj, Itahari and Chitwan in Nepal. The old system is the major problem of the company because the system cannot maintain and update the record of employee. In the new system I’m requested to make new system which can be updated, retrieve, add and delete the details of employee anytime. To make system more effective I’m requested to use Visual Basic .Net using GUI base and also needs to include MS-Access, SQL as database program as back end. The company needs to make four main modules like User Section, Employee Section, Department Section and Account Section. For this I’ve researched the company’s needs and I’ve presented it below: OBJECT ORIENTED PROGRAMMING P a g e 25 | 145 Identifying the objects and data and file structures of the Cloud Infosys Pvt. Ltd. according to given scenario. Company Name Cloud Infosys PVT.LTD. Software Name Employee Information System Program that is used Visual C# .Net Database MS-Access/SQL Programming Platform GUI Based Delivery Environment Desktop Based Software Software Development Environment Visual Studio .Net Modules of Program/Software User Section Employee Section Department Section Account Section Identification of a class User Class Employee Class Department Class Account Class Table 1: Research of company OBJECT ORIENTED PROGRAMMING P a g e 26 | 145 Class Methods Data Members and Types user Add_User() Retrieve_User() Upadate_User() Delete_User() User_id: integer User_name: string User_password: integer Employee Add_Employee() Retrieve_Employee() Update_Employee() Delete_Employee() Employee_id: integer Employee_name: string Employee_gender: string Employee_address: string Employee_ContactNo: integer Employee_email: string Employee_DOB: integer Employee_Depart: string Employee_salary: float Employee_job_title: string Department Add_department() Retrieve_department() Update_department() Delete_department() Department_id: integer Department_name: string Department_head: string Employee_id: integer Account Add_account() Retrieve_acccount() Update_account() Delete_account() Account_id: integer Employee_name: string Employee_ContactNo: integer Employee_address: string Employee_id: integer Department_id: integer Employee_salary: float Table 2: Class, Methods and Data Members including its types. OBJECT ORIENTED PROGRAMMING P a g e 29 | 145 Data Dictionary of Database Employee Information System Table Name Table Name with their Column Name. Column Name with Data type, their size and Constraints Name. Remarks Employee Table This database table is used to store employee details into the database. Department Table This Database table is used to store department information. User Table This database table is used to store user credentials. Role Table This database table is used to store user role. Table 3: Data Dictionary OBJECT ORIENTED PROGRAMMING P a g e 30 | 145 2.2 GUI Design Considerations: 1. Login Form Fig: Login Form Table 1: Properties Setting for the Controls used in Login form. Control Name Setting of some required Properties of the used controls (Name) Text Accept Button Form1 FormLogin User Authentication btnLogin Label1 User Role Label2 User Name Label3 Password Label4 lblError “Error: Invalid Credentials” Label5 Welcome to Employee Information System ComboBox1 cmbUserRole User Role TextBox1 txtUserName User Name TextBox2 txtPassword Password Button1 btnLogin Login Button2 btnCancel Password GroupBox1 Provide User Credentials OBJECT ORIENTED PROGRAMMING P a g e 31 | 145 PictureBox1 2. Main Form Design [Administrator Interface] Fig: Main Form Table 2 : Properties Setting for the Controls used in Main form [Administrator] Interface. Control Name Setting of Main Form Members Sub Members Name Text Window State MDI Container Form1 Form Main Administrator Employee Informatio n System Maximize d True MenuStri p1 User Administ ration Manage Role Manage User Employe e Manage Employee Search Employee Departme nt Manage Department Account Manage Salary OBJECT ORIENTED PROGRAMMING P a g e 34 | 145 Table 4: Properties Setting for the Controls used in User Role Management Form. Control Name Setting of some required Properties of the used controls (Name) Text Accept Button Form1 FormRole Manage Role btnAddRole Label1 Manage User Role Label2 RoleId Label3 RoleName Label4 Role Description TextBox1 txtRoleID TextBox2 txtRoleName TextBox3 txtRoleDesc Button1 btnAddRole Add Role Button2 btnUpdateRole Update Role Button3 btnDeleteRole Delete Role Button4 btnReset Reset Fields Button5 btnExit Exit DataGridView1 dgvRole GroupBox1 View User Role Information GroupBox2 Manage User Role GroupBox3 OBJECT ORIENTED PROGRAMMING P a g e 35 | 145 5. Department Management Form Fig: Department Management Form Table 5: Properties Setting for the Controls used in Department Management Form. Control Name Setting of some required Properties of the used controls (Name) Text Accept Button Form1 FormDepartment Manage Department Section btnCreateDept Label1 Manage Departments Label2 Department ID Label3 Department Name Label4 Description TextBox1 txtDepartmentId TextBox2 txtDepartmentName TextBox3 txtDepartmentDesc Button1 btnCreateDept Add Role Button2 btnUpdateDept Update Role OBJECT ORIENTED PROGRAMMING P a g e 36 | 145 Button3 btnDeleteDept Delete Role Button4 btnReset Reset Fields Button5 btnExit Exit DataGridView1 dgvDepartment GroupBox1 View Department Information GroupBox2 Manage Department Section GroupBox3 6. Manage Employee Form Fig: Employee Management Form Table 6: Properties Setting for the Controls used in Department Management Form. Control Name Setting of some required Properties of the used controls (Name) Text Accept Button OBJECT ORIENTED PROGRAMMING P a g e 39 | 145 8. Class Diagram OBJECT ORIENTED PROGRAMMING P a g e 40 | 145 OBJECT ORIENTED PROGRAMMING P a g e 41 | 145 OBJECT ORIENTED PROGRAMMING P a g e 44 | 145 OBJECT ORIENTED PROGRAMMING P a g e 45 | 145 9. Conclusion In this way, we can design all the necessary diagrams, database and GUI needed to implement Employee Information System. OBJECT ORIENTED PROGRAMMING P a g e 46 | 145 Task 3 I. Implement an object oriented solution based on a prepared design. While implementing you need to define relationships between objects to implement design requirements [3.1, 3.2, D2] II. Implement object behaviors using control structures to meet the design algorithms then make effective use of an Integrated Development Environment (IDE), including code and screen Templates. [3.3, 3.4, M2] Consider: you are required to write code for a complete system considering the design you have prepared in task 2. Then, the outcomes of the implementation should be demonstrated as the screenshots of design view of the user interface along with code. In order to achieve M2, your writing need to demonstrate that a range of methods, tools and techniques have been applied to implement the system in accordance with the agreed design. In order to achieve D2, your writing needs to show that Activities have been managed and organized when implementing the object oriented solution based on prepared design OBJECT ORIENTED PROGRAMMING P a g e 49 | 145 2. Implementation of the Employee Information System in task 2.2. Implementation Architecture [3-Tier Architecture] Solution Name Tier Tier Name Components EISPro Tier-1 EISDataAccessLayer ClassDatabaseConnection ClassRole ClassUser ClassDepartment ClassManageEmployee EISPro Tier-2 EISPresentationLayer FormLogin FormMainAdministrator FormMainUser FormUser FormRole FormDepartment FormManageEmployee FormSearchEmployee EISPro Tier-3 EISBusinessLogicLayer ClassBusinessLogic Implementation of all Classes of EISDataAccessLayer. 2.1 ClassDatabaseConnection using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; using System.Data; OBJECT ORIENTED PROGRAMMING P a g e 50 | 145 namespace EISDataAccessLayer { public class ClassDatabaseConnection { public static string DbConnection { get{returnSystem.Configuration.ConfigurationManager.ConnectionStrings["dbconnection"].Con nectionString; } } } } 2.2. ClassRole using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; namespace EISDataAccessLayer { public class ClassRole { SqlConnection conn = new SqlConnection(ClassDatabaseConnection.DbConnection); public int ManageRole(String RoleId, String RoleName, String RoleDesc, int Mode) { try OBJECT ORIENTED PROGRAMMING P a g e 51 | 145 { int result = 0; string ManageRole = ""; if (Mode == 1) ManageRole = "insert into RoleTable values('" + RoleId + "','" + RoleName + "','" + RoleDesc + "')"; else if (Mode == 2) ManageRole = "Update RoleTable set RoleName='" + RoleName + "',RoleDesc='" + RoleDesc + "' where RoleId='" + RoleId + "'"; else if (Mode == 3) ManageRole = "Delete from RoleTable where RoleId ='" + RoleId + "'"; SqlCommand cmd = new SqlCommand(ManageRole, conn); conn.Open(); result = cmd.ExecuteNonQuery(); conn.Close(); return result; } catch (Exception ex) { throw ex; } } public DataTable GetAllRoles() { try { SqlCommand cmd = new SqlCommand("Select * from RoleTable", conn); conn.Open(); DataTable dt = new DataTable(); OBJECT ORIENTED PROGRAMMING P a g e 54 | 145 conn.Open(); DataTable dt = new DataTable(); SqlDataReader dr = cmd.ExecuteReader(); dt.Load(dr); conn.Close(); return dt; } catch (Exception ex) { throw ex; } } } } 2.4. ClassDepartment using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; namespace EISDataAccessLayer { public class ClassDepartment { OBJECT ORIENTED PROGRAMMING P a g e 55 | 145 SqlConnection conn = new SqlConnection(ClassDatabaseConnection.DbConnection); public int ManageDepartment(String DepartmentId, String DepartmentName, String DepartmentDesc, int Mode) { try { int result = 0; String dept = ""; if (Mode == 1) dept = "insert into DepartmentTable values('" + DepartmentId + "','" + DepartmentName + "','" + DepartmentDesc + "')"; else if (Mode == 2) dept = "Update DepartmentTable set DepartmentName='" + DepartmentName + "',DepartmentDesc='" + DepartmentDesc + "' where DepartmentId='" + DepartmentId + "'"; else if (Mode == 3) dept = "Delete from DepartmentTable where DepartmentId='" + DepartmentId + "'"; SqlCommand cmd = new SqlCommand(dept, conn); conn.Open(); result = cmd.ExecuteNonQuery(); conn.Close(); return result; } catch (Exception ex) { throw ex; } } public DataTable SelectAllDepartments() OBJECT ORIENTED PROGRAMMING P a g e 56 | 145 { try { SqlCommand cmd = new SqlCommand("Select * from DepartmentTable", conn); DataTable dt = new DataTable(); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); dt.Load(dr); conn.Close(); return dt; } catch (Exception ex) { throw ex; } } } } 2.5. ClassManageEmployee using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; OBJECT ORIENTED PROGRAMMING P a g e 59 | 145 DataTable dt = new DataTable(); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); dt.Load(dr); conn.Close(); return dt; } catch (Exception ex) { throw ex; } } public DataSet SelectEmployeeById(String EmployeeId) { try { DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter("Select EmployeeName,Gender,BirthDate,ContactAddress,ContactNumber,WorkingDepartment,HireDa te,JobTitle,BasicSalary,JobStatus,Email from EmployeeTable where EmployeeId='" + EmployeeId + "'", conn); da.Fill(ds); return ds; } catch (Exception ex) { OBJECT ORIENTED PROGRAMMING P a g e 60 | 145 throw ex; } } public DataSet SelectEmployeeByName(String EmployeeName) { try { DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter("Select EmployeeId,Gender,BirthDate,ContactAddress,ContactNumber,WorkingDepartment,HireDate,J obTitle,BasicSalary,JobStatus,Email from EmployeeTable where EmployeeName like '" + EmployeeName + "'", conn); da.Fill(ds); return ds; } catch (Exception ex) { throw ex; } } } } OBJECT ORIENTED PROGRAMMING P a g e 61 | 145 Implementation of all Classes of EISBusinessLogicLayer using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using EISDataAccessLayer; namespace EISBusinessLogicLayer { public class ClassBusinessLogic { ClassRole rc = new ClassRole(); ClassUser uc = new ClassUser(); ClassDepartment dc = new ClassDepartment(); ClassManageEmployee ec = new ClassManageEmployee(); public bool ManageDepartment(string DepartmentId, string DepartmentName, string DepartmentDesc, int Mode) { int rs = 0; bool result = false; if (Mode == 1) { rs = dc.ManageDepartment(DepartmentId, DepartmentName, DepartmentDesc, Mode); if (rs > 0) { result = true; } else OBJECT ORIENTED PROGRAMMING P a g e 64 | 145 public bool ManageUser(String UserId, String UserName, String Password,String RoleName, int Mode) { bool result = false; int rs = 0; rs = uc.ManageUser(UserId,UserName, Password,RoleName , Mode); if (Mode == 1) { if (rs > 0) result = true; else result = false; } else if (Mode == 2) { if (rs > 0) result = true; else result = false; } else if (Mode == 3) { if (rs > 0) result = true; else result = false; } return result; } public bool ManageEmployee( OBJECT ORIENTED PROGRAMMING P a g e 65 | 145 String EmployeeId, String EmployeeName, String Gender, String BirthDate, String ContactAddress, String ContactNumber, String WorkingDepartment, String HireDate, String JobTitle, Double BasicSalary, String JobStatus, String Email, int Mode ) { bool result = false; int rs = 0; rs = ec.ManageEmployee( EmployeeId, EmployeeName, Gender, BirthDate, ContactAddress, ContactNumber, WorkingDepartment, HireDate, JobTitle, BasicSalary, JobStatus, Email, Mode OBJECT ORIENTED PROGRAMMING P a g e 66 | 145 ); if (Mode == 1) { if (rs > 0) result = true; else result = false; } else if (Mode == 2) { if (rs > 0) result = true; else result = false; } else if (Mode == 3) { if (rs > 0) result = true; else result = false; } return result; } } } OBJECT ORIENTED PROGRAMMING P a g e 69 | 145 { cmbRole.DataSource = RoleClass.GetAllRoles(); // when form login loads then it loads combobox used for User role cmbRole.DisplayMember = "RoleName"; cmbRole.ValueMember = "RoleName"; cmbRole.SelectedIndex = -1; txtPassword.Clear(); txtUserName.Clear(); lblError.Visible = false; } private void ResetLoginForm() // To reset Fields { txtPassword.Clear(); txtUserName.Clear(); cmbRole.SelectedIndex = -1; lblError.Visible = false; } private void btnLogin_Click(object sender, EventArgs e) { if (txtPassword.Text == "" || txtUserName.Text == "" || cmbRole.SelectedIndex < 0) { MessageBox.Show("Please Fill All necessary Fields", "ACTION REQUIRED"); } else { try OBJECT ORIENTED PROGRAMMING P a g e 70 | 145 { SqlDataAdapter dAdapter = new SqlDataAdapter("select * from UserTable where RoleName='" + cmbRole.Text + "' and UserName='" + txtUserName.Text + "' and Password='" + txtPassword.Text + "'", con); DataSet dSet = new DataSet(); bool restult = Convert.ToBoolean(dAdapter.Fill(dSet)); if (restult == false) { lblError.Visible = true; cmbRole.SelectedIndex = -1; txtUserName.Clear(); txtPassword.Clear(); return; } else if (restult == true) { if (cmbRole.Text == "Administrator") { ShowUser = txtUserName.Text; this.Hide(); FormMainAdministrator fm = new FormMainAdministrator(this ); //display Administrator Interface fm.Show(); } else { this.Hide(); OBJECT ORIENTED PROGRAMMING P a g e 71 | 145 FormMainUser frmMainUser = new FormMainUser(); //display General User Interface frmMainUser.Show(); } } } catch (Exception exp) { MessageBox.Show(exp.Message); } } } private void btnCancel_Click(object sender, EventArgs e) { ResetLoginForm(); } } } OBJECT ORIENTED PROGRAMMING P a g e 74 | 145 private void logOutToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult dR = new DialogResult(); dR = MessageBox.Show("ARE YOU SURE WANT TO LOG OUT???", "CONFIRMATION REQUIRED", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dR == DialogResult.OK) { this.Hide(); FormLogin fl = new FormLogin(); fl.Show(); } } private void FormMainAdministrator_Load(object sender, EventArgs e) { } private void searchEmployeeToolStripMenuItem_Click(object sender, EventArgs e) { FormSearchEmployee fse = new FormSearchEmployee(); fse.MdiParent = this; fse.Show(); } } OBJECT ORIENTED PROGRAMMING P a g e 75 | 145 } 2.10. FormRole Fig: Role Form using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; OBJECT ORIENTED PROGRAMMING P a g e 76 | 145 using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using EISBusinessLogicLayer; using EISDataAccessLayer; namespace EISTestPro { public partial class FormRole : Form { public FormRole() { InitializeComponent(); } ClassBusinessLogic blc = new ClassBusinessLogic(); //creating object of its type ClassRole rc = new ClassRole(); private void FormRole_Load(object sender, EventArgs e) { dgvRole.DataSource = rc.GetAllRoles(); //load Role table into datagrid view control when form loaded } private void dgvRoleDetails_Click(object sender, EventArgs e) { try { txtRoleId.Text = dgvRole.SelectedRows[0].Cells[0].Value.ToString(); // display the content of grid view into textbox when user click cells OBJECT ORIENTED PROGRAMMING P a g e 79 | 145 if (dR == DialogResult.OK) { if (txtRoleName.Text == "") { MessageBox.Show("Please Provide Batch Name First"); return; } else { UpdateRole(); } } } private void UpdateRole() { try { bool result = blc.ManageRole(txtRoleId.Text, txtRoleName.Text, txtRoleDesc.Text, 2); if (result == true) { MessageBox.Show("ROLE SUCCESSFULLY UPDATED"); dgvRole.DataSource = rc.GetAllRoles(); } else { MessageBox.Show("ERRORS IN UPDATING ROLE"); OBJECT ORIENTED PROGRAMMING P a g e 80 | 145 } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btndeleterole_Click(object sender, EventArgs e) { DialogResult dR = new DialogResult(); dR = MessageBox.Show("ARE YOU SURE WANT TO DELETE???", "CONFIRMATION REQUIRED", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dR == DialogResult.OK) { DeleteRole(); } else { return; } } private void DeleteRole() { try { bool result = blc.ManageRole(txtRoleId.Text, txtRoleName.Text, txtRoleDesc.Text, 3); if (result == true) OBJECT ORIENTED PROGRAMMING P a g e 81 | 145 { MessageBox.Show("ROLE SUCCESSFULLY DELETED"); dgvRole.DataSource = rc.GetAllRoles(); } else { MessageBox.Show("ERRORS IN DELETING ROLE"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void dgvRole_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewRow row = dgvRole.Rows[e.RowIndex]; txtRoleId.Text = row.Cells[0].Value.ToString(); txtRoleName.Text = row.Cells[1].Value.ToString(); txtRoleDesc.Text = row.Cells[2].Value.ToString(); } } OBJECT ORIENTED PROGRAMMING P a g e 84 | 145 txtUserName.BackColor = Color.Red; return; } else if (txtUserName.Text == "") { MessageBox.Show("PLEASE PROVIDE USERNAME FIRST"); txtUserName.BackColor = Color.Red; return; } else if (txtPassword.Text == "") { MessageBox.Show("PLEASE PROVIDE PASSWORD FIRST"); txtPassword.BackColor = Color.Red; return; } else { NewUser(); } } private void NewUser() { try { bool rs = blc.ManageUser(txtUserId.Text,txtUserName.Text, txtPassword.Text, cmbRole.Text, 1); if (rs == true) { MessageBox.Show("NEW USER SUCCESSFULLY CREATED"); dgvUser.DataSource = uc.SelectAllUsers(); OBJECT ORIENTED PROGRAMMING P a g e 85 | 145 } else { MessageBox.Show("SOME ERRORS OCCURED"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void dgvUserDetails_Click(object sender, EventArgs e) { try { txtUserId.Text = dgvUser.SelectedRows[0].Cells[0].Value.ToString(); txtUserName.Text = dgvUser.SelectedRows[0].Cells[2].Value.ToString(); txtPassword.Text = dgvUser.SelectedRows[0].Cells[4].Value.ToString(); cmbRole.Text = dgvUser.SelectedRows[0].Cells[5].Value.ToString(); } catch (Exception) { throw; } } OBJECT ORIENTED PROGRAMMING P a g e 86 | 145 private void btnupdateuser_Click(object sender, EventArgs e) { DialogResult dR = new DialogResult(); dR = MessageBox.Show("ARE YOU SURE TO UPDATE???", "CONFIRMATION REQUIRED", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dR == DialogResult.OK) { if (txtPassword.Text == "" || txtUserName.Text == "") { MessageBox.Show("User Name or Password Field Cannot be Blank"); return; } else { UpdateUser(); ClearUserFields(); } } } private void UpdateUser() { try { bool rs = blc.ManageUser(txtUserId.Text, cmbRole.Text, txtUserName.Text, txtPassword.Text, 2); if (rs == true) { MessageBox.Show("NEW USER SUCCESSFULLY UPDATED"); OBJECT ORIENTED PROGRAMMING P a g e 89 | 145 private void btnClear_Click(object sender, EventArgs e) { ClearUserFields(); } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void dgvUser_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewRow row = dgvUser.Rows[e.RowIndex]; txtUserId.Text = row.Cells[0].Value.ToString(); txtUserName.Text = row.Cells[1].Value.ToString(); txtPassword.Text = row.Cells[2].Value.ToString(); cmbRole.Text = row.Cells[3].Value.ToString(); } } } } OBJECT ORIENTED PROGRAMMING P a g e 90 | 145 2.12. FormDepartment Fig: Department Form using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using EISDataAccessLayer; using EISBusinessLogicLayer; namespace EISTestPro OBJECT ORIENTED PROGRAMMING P a g e 91 | 145 { public partial class FormDepartment : Form { public FormDepartment() { InitializeComponent(); } ClassBusinessLogic blc = new ClassBusinessLogic(); ClassDepartment dc = new ClassDepartment(); private void FormDepartment_Load(object sender, EventArgs e) { dgvDepartment.DataSource = dc.SelectAllDepartments(); } private void btncreatedept_Click(object sender, EventArgs e) { if (txtDepartmentId.Text == "") { MessageBox.Show("DEPARTMENT ID CANNOT BE BLANK"); } else if (txtDepartmentName.Text == "") { MessageBox.Show("DEPARTMENT NAME CANNOT BE BLANK"); } else if (txtDepartmentDesc.Text == "") { MessageBox.Show("THE DESCRIPTION FIELD CANNOT BE BLANK"); OBJECT ORIENTED PROGRAMMING P a g e 94 | 145 else { return; } } private void ClearUserFields() { txtDepartmentDesc.Clear(); txtDepartmentId.Clear(); txtDepartmentName.Clear(); } private void btnClear_Click(object sender, EventArgs e) { ClearUserFields(); } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void dgvDepartment_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewRow row = dgvDepartment.Rows[e.RowIndex]; txtDepartmentId.Text = row.Cells[0].Value.ToString(); txtDepartmentName.Text = row.Cells[1].Value.ToString(); txtDepartmentDesc.Text = row.Cells[2].Value.ToString(); } } OBJECT ORIENTED PROGRAMMING P a g e 95 | 145 } } 2.13.FormManageEmployee Fig: Employee Manage Form using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using EISBusinessLogicLayer; using EISDataAccessLayer; namespace EISTestPro OBJECT ORIENTED PROGRAMMING P a g e 96 | 145 { public partial class FormManageEmployee : Form { public FormManageEmployee() { InitializeComponent(); } ClassDepartment cd = new ClassDepartment(); ClassManageEmployee me = new ClassManageEmployee(); ClassBusinessLogic blc = new ClassBusinessLogic (); private void FormManageEmployee_Load(object sender, EventArgs e) { try { cmbWorkingDept.DataSource = cd.SelectAllDepartments(); cmbWorkingDept.ValueMember = "DepartmentName"; cmbWorkingDept.DisplayMember = "DepartmentName"; cmbWorkingDept.SelectedIndex = -1; dgvEmployee.DataSource = me.SelectAllEmployees(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }