Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

Informatics College Pokhara

Application Development
CS6004NA
Coursework 1

Submitted By: Submitted To:


Student Name: Aashish Parajuli Mr. Ashim Batajoo
London Met ID: 17031949 Application Development
Group: L3C2
Date: 25th-Jan-2018
Abstract
This is an individual course work for the module “Application Development” for
Museum Management System which is developed using Visual Studio Platform
using C# language. The coursework is released in the week 8 and it is
supposed to be submitted in the week 12.

With the great contribution of Mr. Ashim Batajoo the course work was
completed within the time frame.
Table of Contents
1. Introduction ............................................................................................... 1
1.1 Current Scenario ................................................................................. 1
1.2 Proposed System ............................................................................... 1
2. User Manual ............................................................................................. 2
3. Journal Articles ....................................................................................... 18
4. System Architecture................................................................................ 20
Class Diagram ............................................................................................ 21
Individual Diagram ...................................................................................... 22
Flowchart for Reports ................................................................................. 28
Daily Report ............................................................................................ 28
Weekly Report ........................................................................................ 29
Algorithms of Reports ................................................................................. 30
Daily Report ............................................................................................ 30
Weekly Report ........................................................................................ 30
5. Sorting Algorithm .................................................................................... 31
6. Reflection ................................................................................................ 33
7. Conclusion .............................................................................................. 34
Bibliography ................................................................................................... 35
References .................................................................................................... 36
Appendix ........................................................................................................ 37
Table of Figure
Figure 1 Login Screen...................................................................................... 2
Figure 2 Main Screen....................................................................................... 3
Figure 3 Visitor Entry Section .......................................................................... 4
Figure 4 Museum Closed message ................................................................. 5
Figure 5 Museum opening message ................................................................ 5
Figure 6 Add Visitor Entry Details Screen ........................................................ 6
Figure 7 Visitor Entry Detail Added successfully .............................................. 7
Figure 8 Dialog Screen for exporting data ....................................................... 7
Figure 9 CSV data in Microsoft Excel .............................................................. 8
Figure 10 Import from CSV dialog.................................................................... 8
Figure 11 Data imported from CSV file ............................................................ 9
Figure 12 Unsorted Data ................................................................................ 10
Figure 13 Sorted Data as per total minutes ................................................... 11
Figure 14 Visitor Detail Screen ...................................................................... 11
Figure 15 Visitor Name in Combo Box ........................................................... 12
Figure 16 Invalid Email notification ................................................................ 12
Figure 17 Valid Visitor Detail Data ................................................................. 13
Figure 18 Visitor Details added successfully .................................................. 13
Figure 19 Daily Report Screen ....................................................................... 14
Figure 20 Chart Display of Daily Report......................................................... 15
Figure 21 List view of Daily Report ................................................................ 15
Figure 22 Weekly Report Screen ................................................................... 16
Figure 23 Weekly Chart ................................................................................. 16
Figure 24 List view of Weekly Report............................................................. 17
Figure 25 Architecture Diagram ..................................................................... 20
Figure 26 Class Diagram ............................................................................... 21
Figure 27 Visitor Repository Individual Diagram ............................................ 22
Figure 28 VisitorEntryDetail ........................................................................... 24
Figure 29 weeklyReportChart ........................................................................ 25
Figure 30 DailyReportChart ........................................................................... 26
Figure 31 Flowchart for Daily Report ............................................................. 28
Figure 32 Flowchart for Weekly Chart............................................................ 29
Figure 33 Flowchart for Weekly Chart............................................................ 30
CS6004NA Application Development

1. Introduction
The designed system is Museum Management System. The system is
highly designed developed and test under various circumstances. The
features and functions that are required by Museum are almost fulfilled by
the developed system. It consist of features like adding visitor’s entry and
exit time and calculate the total minutes spend by the visitor. In addition to
that, details information of the entered visitor can be added such as their
first name, email address, contact number and occupation. Furthermore,
there is a features to view daily and weekly table and chart. Other available
features are well explained in other sections of the report.

1.1 Current Scenario


There are numerous Museum who keep record of their data in old
traditional system which is Paper-Based System. In addition to that,
there are some museum with digital system but are well lacking the
features which are needed for a Museum.

1.2 Proposed System


The proposed system is digitized system which is specially designed
to overcome problem mentioned above. The system ensures security
with the presence of login section. Entry of data and display of data
have been made easy with the presence of easy user-interface.

Page | 1
CS6004NA Application Development

2. User Manual
There are screenshot below which will illustrate a user how to operate the
system.

As the end user operates the system the initial screen will be the security
screen. The username and password of the system is “admin”. Only a valid
username and password can provide access to the system.

Figure 1 Login Screen

Page | 2
CS6004NA Application Development

After successful login the main screen of the system appears.

Figure 2 Main Screen


The main screen provides three service which are Visitor Entry section, Visitor
Detail section and Report section.

Page | 3
CS6004NA Application Development

To check all the data about visitor entry and to add new visitor user should
simply click in the ‘Visitor Entry’ option from the top right corner. As the user
clicks following screen will appear.

Figure 3 Visitor Entry Section


As the user visits the Visitor Entry Section user have six features to work with.
The first feature is to add the details of the visitor’s entry to the museum which
includes the date, day is automatically taken by the system, visitor’s entry and
exit time.

A user can only allow to use this feature from Monday to Friday and within the
time frame of 10 A.M to 5 P.M. The following message will display when above
condition is not satisfied.

Page | 4
CS6004NA Application Development

Figure 4 Museum Closed message

Figure 5 Museum opening message

Page | 5
CS6004NA Application Development

When the user access the system in a valid day and time can now access the
facility of adding visitor entry details.

Figure 6 Add Visitor Entry Details Screen


A user cannot add numeric values into the Card Name section as the field is
validated. As the user inputs Name and sets the in time and out time system
add data into the grid as shown below.

Page | 6
CS6004NA Application Development

Figure 7 Visitor Entry Detail Added successfully


A user can export the data into a CSV file and check in Microsoft Excel. The
user should click on ‘Export to CSV’ and following screen will appear.

Figure 8 Dialog Screen for exporting data

Page | 7
CS6004NA Application Development

Data are displayed in the Excel as shown below:

Figure 9 CSV data in Microsoft Excel


A user can import the data from CSV file into the grid as below.

Figure 10 Import from CSV dialog

Page | 8
CS6004NA Application Development

The data will be displayed in the grid as shown below.

Figure 11 Data imported from CSV file

Page | 9
CS6004NA Application Development

As the user keep adding data, added data are displayed in an unsorted format
which looks alike.

Figure 12 Unsorted Data

An end user can sort data present in the grid by clicking on ‘Sort by Total
Minutes’ which is present in bottom left corner. The sorted data looks alike.

Page | 10
CS6004NA Application Development

Figure 13 Sorted Data as per total minutes


As the user add all the visitor entry details a user can add details such as first
name, email address, occupation and phone number. A user should simply click
on ‘Visitor Details’ from the top left corner.

Figure 14 Visitor Detail Screen

Page | 11
CS6004NA Application Development

A visitor that has entered into museum needs to provide their details such as
Last Name, email address, phone number and occupation. The entered visitor
are displayed in the combo box as shown below.

Figure 15 Visitor Name in Combo Box


A user should provide a valid email address otherwise the system will display
following message as shown in the image below.

Figure 16 Invalid Email notification

Page | 12
CS6004NA Application Development

In the context of adding number a user can provide number including +977-. In
Last name and occupation section numeric value cannot be entered. A valid
data looks like:

Figure 17 Valid Visitor Detail Data


As the user click on the save button after adding valid data as shown above the
data will be displayed as shown below.

Figure 18 Visitor Details added successfully

Page | 13
CS6004NA Application Development

The feature which are present such as ‘Import from CSV’, ‘Export to CSV’, Save
( Serialize ), and Retrieve (Deserialize) works the same as in the Visitor Entry
Detail Screen.
In addition to that, a key feature is the report section. Report features like Daily
Report and Chart and Weekly Report and Chart. To access the report section
a user should click on the Report section and choose either Daily or Weekly.
Accessing the Daily Section. The following screen will appear.

Figure 19 Daily Report Screen

Page | 14
CS6004NA Application Development

To view the Daily Detail in a chart section a user should simply click on Display
Chart and following screen will appear.

Figure 20 Chart Display of Daily Report


To view the data into a list view a user can simply click on ‘Display Sorted List’
and following screen will appear.

Figure 21 List view of Daily Report

Page | 15
CS6004NA Application Development

Accessing the Weekly Section. The following screen will appear.

Figure 22 Weekly Report Screen


To view the Weekly Detail in a chart section a user should simply click on
Display Chart and following screen will appear.

Figure 23 Weekly Chart

Page | 16
CS6004NA Application Development

To view the data into a list view a user can simply click on ‘Display Sorted List’
and following screen will appear.

Figure 24 List view of Weekly Report

Page | 17
CS6004NA Application Development

3. Journal Articles
I. New technologies are commencement to cause important changes in the
way museums execute their functions and in the way they are supposed by
the public. The rapid adaptation of text and images into digital form will affect
work procedures within the museum. Attached with the advent of high speed
digital systems, this union will permit the museum to offer more info to a
wider overall public (Jones-Garmil, 2014).

II. In this paper we present an approach for modified access to museum


assortments. We use a RDF/OWL specification of the Rijksmuseum
Amsterdam collections as a driver for an interactive dialog. The user gives
his/her judgment on the artefacts, representing likes or dislikes. The elicited
user model is further used for generating references of articles and topics.
In this way we support study and finding of info in museum assortments. A
user study providing visions in features of our goal user group, and showed
how novice and expert users employ their related information and implicit
(Williams, 2012).

III. The connection among museums and mass media as well as the likely
impact of info technology on museums are labelled. The “virtual museum”
is defined as a means to establish access, context, and outreach by using
information technology. The Internet opens the “virtual museum” to a
cooperating dialog with virtual visitors and invites them to make a virtual
museum familiarity that is related to a real museum experience. Some
research is described on how the Internet can be used as a information base
and trends from surveys how museums and virtual visitors use the Internet
as a communication tool (Schweibenz, 2004).

Page | 18
CS6004NA Application Development

IV. The museum offers a initial point from which to inspect the fundamental
nature of collaborative work and interdisciplinary scholarship. This article
examines the socio-technological influence of presenting progressive
information technology into the Spurlock Museum, a museum of world
history and culture at the University of Illinois. It speaks the operation of
such methodologies as computer-supported cooperative work (CSCW) and
computer-mediated communication (CMC) in the museum environment
(Marty, n.d.).

Page | 19
CS6004NA Application Development

4. System Architecture
Architecture Diagram

Figure 25 Architecture Diagram

Page | 20
CS6004NA Application Development

Class Diagram

Figure 26 Class Diagram

Page | 21
CS6004NA Application Development

Individual Diagram
1. VisitorRepository
Methods Description Diagram
DeserializeVisitorDataDeserialization of
visitor data.
ExportToCSV Exporting visitor details
into a csv file.
GenerateId Generating a primary
id of visitor for
respective data.
ReadFromCSV Read the visitor data
that are available in a
CSV file.
SerializeVisitorData Serialization of visitor’s
data.
SortUsingTotalMinutes Sorting the user data
as per Total Minutes.

Figure 27 Visitor Repository Individual Diagram

Page | 22
CS6004NA Application Development

2. VisitorEntry
Methods Description Diagram
cardNametextBox It is used for taking
input of Card Name of
the Visitor.
VisitorEntry_Load To add features when
the Visitor Entry screen
loads.

Page | 23
CS6004NA Application Development

3. VisitorEntryDetail
Methods Description Diagram
ExportToCSV Exporting visitor
details into a csv
file.
ReadFromCSV Read the visitor
data that are
available in a
CSV file.
retrieveDeserializeVisitorData Deserialization of
visitor data.

Figure 28 VisitorEntryDetail

Page | 24
CS6004NA Application Development

4. weeklyReportChart
Methods Description Diagram
displayChartButton To visit the daily chart
as per the daily report.
displayTableButton To visit the table of the
daily data.
LoadVisitorDetial To load the visitor
details and add then in
chart and in list.
pictureBox1_Click This is the exit icon
added in the screen
and which is used to
terminate the form.

Figure 29 weeklyReportChart

Page | 25
CS6004NA Application Development

5. DailyReportChart
Methods Description Diagram
displayChartButton To visit the weekly
chart as per the weekly
report.
displayTableButton To visit the table of the
daily data.
LoadVisitorDetial To load the visitor
details and add then in
chart and in list.
pictureBox1_Click This is the exit icon
added in the screen
and which is used to
terminate the form.

Figure 30 DailyReportChart

Page | 26
CS6004NA Application Development

6. Login
Methods Description Diagram
ErrorMess It is used to display the
error message when
username and
password are not
correct.
Logbtn_Click It is used to validate
the username and
password and let user
enter the system when
username and
password are correct.
pictureBox2_Click It is used to terminate
the program.

Page | 27
CS6004NA Application Development

Flowchart for Reports


Daily Report

Figure 31 Flowchart for Daily Report

Page | 28
CS6004NA Application Development

Weekly Report

Figure 32 Flowchart for Weekly Chart

Page | 29
CS6004NA Application Development

Figure 33 Flowchart for Weekly Chart

Algorithms of Reports
Daily Report
Steps:

1. Start

2. Check whether the visitor entry data file exists or not.

3. If it doesn’t exists, display error message and restart

4. If exists, read the available data

5. Check whether there is visitor entry data of the particular day or not

6. If data doesn’t exist, display error message and restart

7. If data found, retrieve the data

8. Display the data in the Bar chart

9. Stop

Weekly Report
Steps:

1. Start

2. Check whether the visitor entry data file exists or not.

3. If it doesn’t exists, display error message and restart

4. If exists, read the available data

5. Check whether there is visitor entry data or not

6. If data doesn’t exist, display error message and restart

7. If data found, retrieve the data

8. Display the data in the Bar chart

9. Stop

Page | 30
CS6004NA Application Development

5. Sorting Algorithm
The sorting Algorithm used in the Museum System is bubble sorting
algorithm.
Bubble sort is a basic arranging calculation. This arranging calculation is
correlation based calculation in which each match of neighbouring
components is analysed and the components are swapped in the event
that they are not altogether. This calculation isn't reasonable for substantial
informational indexes as its normal and most pessimistic scenario
multifaceted nature are of Ο(n2) where n is the quantity of things.

Working Mechanism:

We take an unsorted array for our example. Bubble sort takes Ο(n 2) time
so we're keeping it short and precise.

Bubble sort starts with very first two elements, comparing them to check
which one is greater.

In this case, value 33 is greater than 14, so it is already in sorted locations.


Next, we compare 33 with 27.

We find that 27 is smaller than 33 and these two values must be swapped.

The new array should look like this −

Page | 31
CS6004NA Application Development

Next we compare 33 and 35. We find that both are in already sorted
positions.

Then we move to the next two values, 35 and 10.

We know then that 10 is smaller 35. Hence they are not sorted.

We swap these values. We find that we have reached the end of the array.
After one iteration, the array should look like this −

To be precise, we are now showing how an array should look like after
each iteration. After the second iteration, it should look like this −

Notice that after each iteration, at least one value moves at the end.

And when there's no swap required, bubble sorts learns that an array is
completely sorted.

Now we should look into some practical aspects of bubble sort.

Page | 32
CS6004NA Application Development

6. Reflection
The developed system is Digitalized Museum Management System. It is
developed using Visual Studio 2017 with the C# language version 7.3. The
business logic used in the system reflects the real working environment of
the Museum. The GUI designed is highly user interface and user with basic
system administration can operate the system.

An end user can have the facilities of add the In Time and Out Time of the
visitor along with their name. The total duration spend by the visitor is
calculated automatically by the system. The details of the entered visitor
can be added such as: Last Name, phone number, email address and
occupation can be added manually by the user. In addition to that, a user
can check out the daily and weekly chart along with the list.

I had some previous experience with Visual Studio. With this experience I
had got some plus point while doing this coursework. I came to get more
working and experience with the language. Features like creating chart
generating list In addition to that, sorting of data form the grid was a new
thing for me. Furthermore, import and exporting to CSV file was new aspect
for me. Overall evaluation with the great support of Mr. Ashim Batajoo I
had a great experience with the Application Development of the Museum.

Page | 33
CS6004NA Application Development

7. Conclusion
The initial coursework for the module CS6004NA Application Development
was to build up a guest the executives framework for an exhibition hall. It
required a long time to build up the task in Visual Studio Enterprise 2017
utilizing C# programming dialect. The framework has login screen to add
security to the task. After login, the framework shows a primary screen
where every one of the functionalities are found. Aside from various shape
components, class outline for every one of the structures and classes were
utilized.

I would like to thank my supervisor Mr. Ashim Batajoo for guiding me


throughout the project.

Page | 34
CS6004NA Application Development

Bibliography
Jones-Garmil, 2014. The Transformation of the Museum and the Way it's
Perceived..
Marty, n.d. Museum informatics and collaborative technologies: The emerging
socio-technological dimension of information science in museum environments.
2012.
Schweibenz, 2004. Virtual Museum.
Williams, 2012. Microsoft Visual C# (Core Reference). s.l.:Microsoft Press
Redmond..

Page | 35
CS6004NA Application Development

References
Erichero, (2008). Create One Application for both Desktop and Web. [Online]
Available at: https://www.codeproject.com/Articles/30542/Create-One-
Application-for-both-Desktop-and-Web [Accessed 24th January, 2019]
Sharp, J., 2018. Microsoft Visual C# Step by Step (9th Edition) (developer
Reference). Microsoft Press.
Working with C# List (Code Examples). 2019. Working with C# List (Code
Examples). [ONLINE] Available at: https://www.c-sharpcorner.com/article/c-
sharp-list/. [Accessed 24 January 2019].
dotnet-bot. 2019. Data Binding Overview | Microsoft Docs. [ONLINE] Available
at: https://docs.microsoft.com/en-us/dotnet/framework/wpf/data/data-binding-
overview. [Accessed 24 January 2019].
Dot Net for All. 2019. Bubble Sort with Simple Explanation in C# • Dot Net for
All. [ONLINE] Available at: https://www.dotnetforall.com/bubble-sort-simple-
explanation-c/. [Accessed 24 January 2019].
rpetrusha. 2019. How to: Verify that Strings Are in Valid Email Format |
Microsoft Docs. [ONLINE] Available at: https://docs.microsoft.com/en-
us/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-
format. [Accessed 24 January 2019].
Liberty, J., 2003. Programming C#, Third Edition. O'reilly Media.
tutorialspoint.com. 2019. Data Structures and Algorithms Bubble Sort.
[ONLINE] Available at:
https://www.tutorialspoint.com/data_structures_algorithms/bubble_sort_algorit
hm.htm. [Accessed 24 January 2019].

Page | 36
CS6004NA Application Development

Appendix
Login.cs
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;

namespace MuseumMgntSystem
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}

// to check whether the username and password are correct or not


private void LogDetail()
{
if (txtUsername.Text == "admin" && txtPassword.Text == "admin")
{
MuseumSystem ms = new MuseumSystem();
this.Hide();
ms.Show();
}
else
{
ErrorMess();
}
}
//error message when username or password is incorrect
private void ErrorMess()
{
MessageBox.Show("Incorrect username or password", "Login Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUsername.Text = "";
txtPassword.Text = "";
txtUsername.Select();
}

private void Logbtn_Click(object sender, EventArgs e)


{
LogDetail();

private void pictureBox2_Click(object sender, EventArgs e)


{
Application.Exit();
}
}
}

Page | 37
CS6004NA Application Development

MuseumSystem.cs
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;

namespace MuseumMgntSystem
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}

// to check whether the username and password are correct or not


private void LogDetail()
{
if (txtUsername.Text == "admin" && txtPassword.Text == "admin")
{
MuseumSystem ms = new MuseumSystem();
this.Hide();
ms.Show();
}
else
{
ErrorMess();
}
}
//error message when username or password is incorrect
private void ErrorMess()
{
MessageBox.Show("Incorrect username or password", "Login Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUsername.Text = "";
txtPassword.Text = "";
txtUsername.Select();
}

private void Logbtn_Click(object sender, EventArgs e)


{
LogDetail();

private void pictureBox2_Click(object sender, EventArgs e)


{
Application.Exit();
}
}
}

Page | 38
CS6004NA Application Development

Visitor.cs
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;

namespace MuseumMgntSystem
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}

// to check whether the username and password are correct or not


private void LogDetail()
{
if (txtUsername.Text == "admin" && txtPassword.Text == "admin")
{
MuseumSystem ms = new MuseumSystem();
this.Hide();
ms.Show();
}
else
{
ErrorMess();
}
}
//error message when username or password is incorrect
private void ErrorMess()
{
MessageBox.Show("Incorrect username or password", "Login Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUsername.Text = "";
txtPassword.Text = "";
txtUsername.Select();
}

private void Logbtn_Click(object sender, EventArgs e)


{
LogDetail();

private void pictureBox2_Click(object sender, EventArgs e)


{
Application.Exit();
}
}
}

Page | 39
CS6004NA Application Development

VisitorDetail.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace MuseumMgntSystem
{
[Serializable()]

public class VisitorDetail : ISerializable


{
public int VisitorDetailId { get; set; }
public string CardName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Contact { get; set; }
public string Occupation { get; set; }

//needed for serialization


public static string KEY = "VisitorDetailId";
public static string KEY1 = "CardName";
public static string KEY2 = "LastName";
public static string KEY3 = "Email";
public static string KEY4 = "Contact";
public static string KEY5 = "Occupation";

public VisitorDetail(SerializationInfo serial, StreamingContext


context)
{
//Get the values from info and assign them to the appropriate
properties

VisitorDetailId = (int)serial.GetValue(KEY, typeof(int));


CardName = (string)serial.GetValue(KEY1, typeof(string));
LastName = (string)serial.GetValue(KEY2, typeof(string));
Email = (string)serial.GetValue(KEY3, typeof(string));
Contact = (string)serial.GetValue(KEY4, typeof(string));
Occupation = (string)serial.GetValue(KEY5, typeof(string));
}

//default constructor
public VisitorDetail() { }

public void GetObjectData(SerializationInfo info, StreamingContext


context)
{
//You can use any custom name for your name-value pair. But make
sure you
// read the values with the same name. For ex:- If you write EmpId
as "EmployeeId"
// then you should read the same with "EmployeeId"
info.AddValue(KEY, VisitorDetailId);
info.AddValue(KEY1, CardName);
info.AddValue(KEY2, LastName);

Page | 40
CS6004NA Application Development

info.AddValue(KEY3, Email);
info.AddValue(KEY4, Contact);
info.AddValue(KEY5, Occupation);
}
}
}

VisitorDetailForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MuseumMgntSystem
{
public partial class VisitorDetailForm : Form
{

private BindingSource _visitorDetailBindingSource = new


BindingSource();
private VisitorDetailRepository _visitorDetailRepository = new
VisitorDetailRepository();
public VisitorDetailForm()
{
InitializeComponent();
}

private void VisitorDetailForm_Load(object sender, EventArgs e)


{
retrievePictureBox_Click(sender, e);
}

private void pictureBox2_Click(object sender, EventArgs e)


{
this.Close();
}

private void addVisitorDetailPictureBox_Click(object sender, EventArgs


e)
{
AddVisitorDetails addVisitor = new AddVisitorDetails();
addVisitor.MaximizeBox = false;
var result = addVisitor.ShowDialog(this);
if (result == DialogResult.OK)
{
var visitorDetail = addVisitor.VisitorDetail;
visitorDetail.VisitorDetailId =
_visitorDetailRepository.GenerateId();
_visitorDetailBindingSource.Add(visitorDetail);

_visitorDetailRepository.SaveVisitorDetails((List<VisitorDetail>)_visitorDetail
BindingSource.DataSource);

Page | 41
CS6004NA Application Development

private void importFromCSVPictureBox_Click(object sender, EventArgs e)


{
//step 1: create an instance of windows default open dialog box.
var dialog = new OpenFileDialog();
//step 2: set filter so that it shows only csv files.
dialog.Filter = "CSV files|*.csv";

//step 3: open the dialog box


var result = dialog.ShowDialog();

//check if user has clicked OK.


if (result == System.Windows.Forms.DialogResult.OK)
{
//Step 1: read all the lines in the csv file
var csvString = File.ReadAllText(dialog.FileName);
//Step 2: Pass the csvString to ReadFromCSV method from
_visitorDetailRepository class
//Step 3: Save the value to the binding source. (Binding Source
is used by our grid).
_visitorDetailBindingSource.DataSource =
_visitorDetailRepository.ReadFromCSV(csvString);
}
}

private void exportToCSVPictureBox_Click(object sender, EventArgs e)


{
//step 1: create an instance of windows default save dialog box.
var dialog = new SaveFileDialog();
//step 2: set filter so that the file can be saved with extenstion
.csv.
dialog.Filter = "CSV File|*.csv";
dialog.AddExtension = true;
//step 3: open the save dialog box
var result = dialog.ShowDialog();

if (result == System.Windows.Forms.DialogResult.OK)
{
//export filename and our data list to the ExportToCSV class.

_visitorDetailRepository.ExportToCSV((List<VisitorDetail>)_visitorDetailBinding
Source.DataSource, dialog.FileName);
}
}

private void savePictureBox_Click(object sender, EventArgs e)


{

_visitorDetailRepository.SaveVisitorDetails((List<VisitorDetail>)_visitorDetail
BindingSource.DataSource);
}

private void retrievePictureBox_Click(object sender, EventArgs e)


{
//to display in grid
_visitorDetailBindingSource.DataSource =
_visitorDetailRepository.GetVisitorDataDetails();

//if set to true creates a new object if the list is empty.


_visitorDetailBindingSource.AllowNew = false;

Page | 42
CS6004NA Application Development

visitorDetailGrid.DataSource = _visitorDetailBindingSource;
visitorDetailGrid.ReadOnly = true;
}
}
}

VisitorDetailRepository.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MuseumMgntSystem
{
public class VisitorDetailRepository
{
private List<VisitorDetail> _visitorDetailList = new
List<VisitorDetail>();
private string filePath =
Path.GetDirectoryName(Application.ExecutablePath);

private void DeSerializeVisitorData()


{
if (File.Exists(filePath + @"\visitorDataDetail.dat"))
{
Stream stream = File.Open(filePath + @"\visitorDataDetail.dat",
FileMode.Open);
if (stream != null && stream.Length > 0)
{
BinaryFormatter binaryFormatter = new BinaryFormatter();

//Reading VisitorDetail Information


_visitorDetailList =
(List<VisitorDetail>)binaryFormatter.Deserialize(stream);

}
stream.Close();
}
}
private void SerializeVisitorData(List<VisitorDetail> visitorDetails)
{
Stream str = File.Open(filePath + @"\visitorDataDetail.dat",
FileMode.Create);
BinaryFormatter bF = new BinaryFormatter();
bF.Serialize(str, visitorDetails);
str.Flush();
str.Close();
MessageBox.Show("Visitor Detail added successfully.", "Data
saved.", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public void SaveVisitorDetails(List<VisitorDetail> visitorDetails)
{
SerializeVisitorData(visitorDetails);
}

Page | 43
CS6004NA Application Development

public List<VisitorDetail> ReadFromCSV(string csvString)


{
var visitorDetailList = new List<VisitorDetail>();
try
{
//1st row contains property name so skipping the first row.
var lines = csvString.Split(new char[] { '\n' },
StringSplitOptions.RemoveEmptyEntries).Skip(1);

foreach (var item in lines)


{
var values = item.Split(',');
var visitorDetail = new VisitorDetail();
visitorDetail.VisitorDetailId = Convert.ToInt32(values[0]);
visitorDetail.CardName = Convert.ToString(values[1]);
visitorDetail.LastName = Convert.ToString(values[2]);
visitorDetail.Email = Convert.ToString(values[3]);
visitorDetail.Contact = Convert.ToString(values[4]);
visitorDetail.Occupation = Convert.ToString(values[5]);
visitorDetailList.Add(visitorDetail);
}
_visitorDetailList = visitorDetailList;

}
catch (Exception ex)
{
MessageBox.Show("Not able to save the data", "Error Saving
data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return visitorDetailList;

}
public int GenerateId()
{
int id = 0;
if (_visitorDetailList != null && _visitorDetailList.Count > 0)
{
id = _visitorDetailList.Max(a => a.VisitorDetailId);
}

return id + 1;
}
public void ExportToCSV(List<VisitorDetail> visitorDetails, string
filePath)
{
try
{
if (visitorDetails.Count > 0)
{
var propList =
visitorDetails[0].GetType().GetProperties().Select(prop => prop.Name).ToList();
//TextWriter is used to create outputand streamWriter is
used to read file location

using (TextWriter TW = new StreamWriter(filePath, append:


true))
{
//writes header
foreach (var prop in propList)
{
TW.Write(prop.ToString() + ",");
}

Page | 44
CS6004NA Application Development

TW.WriteLine();
//writes values
foreach (var val in visitorDetails)
{
foreach (PropertyInfo prop in
val.GetType().GetProperties())
{
TW.Write(prop.GetValue(val, null).ToString() +
",");
}
TW.WriteLine();

}
}
MessageBox.Show("Visitor details saved successfuly", "Saved
Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
Process.Start(filePath);
}
}
catch (Exception ex)
{
MessageBox.Show("Not able to save the data", "Error Saving
data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}
public List<VisitorDetail> GetVisitorDataDetails()
{
DeSerializeVisitorData();
if (_visitorDetailList != null && _visitorDetailList.Count > 0)
{
return _visitorDetailList;
}
else
{
_visitorDetailList = new List<VisitorDetail>();
return _visitorDetailList;
}

}
}
}

VisitorEntry.cs
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;

namespace MuseumMgntSystem
{
public partial class VisitorEntry : Form
{
public VisitorEntry()
{

Page | 45
CS6004NA Application Development

InitializeComponent();
}

public Visitor Visitor


{

get
{

var visitor = new Visitor();


visitor.Date = datePicker.Value.Date;
visitor.Day = datePicker.Value.DayOfWeek.ToString();
visitor.CardName = cardNametextBox.Text;
visitor.InTime = inTimePicker.Value.TimeOfDay;
visitor.OutTime = outTimePicker.Value.TimeOfDay;
visitor.TotalMinutes = visitor.CalculateTotalMinutes();
if (datePicker.Value.DayOfWeek == DayOfWeek.Saturday ||
datePicker.Value.DayOfWeek == DayOfWeek.Sunday)
{
datePicker.Enabled = false;
MessageBox.Show("The entered date is either Saturday or
Sunday so the date is automatically updated to Monday of the same week.",
"Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning);
visitor.Date=
datePicker.Value.Date.AddDays(((int)datePicker.Value.DayOfWeek * -1) + 1);
visitor.Day= visitor.Date.DayOfWeek.ToString();
}
return visitor;

private void VisitorEntry_Load(object sender, EventArgs e)


{
inTimePicker.MinDate = DateTime.Parse("10:00:00");
inTimePicker.MaxDate = DateTime.Parse("16:45:00");

outTimePicker.MinDate = DateTime.Parse("10:01:00");
outTimePicker.MaxDate = DateTime.Parse("16:59:00");

if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday ||
DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
{
MessageBox.Show("The ABC Museum remains closed on weekends.",
"Museum Closed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.Close();
}
if (DateTime.Now <= DateTime.Parse("9:59:00") || DateTime.Now >=
DateTime.Parse("17:00:00"))
{
MessageBox.Show("The ABC Museum opens from 10 A.M to 5 P.M",
"Museum Closed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.Close();
}

private void cardNametextBox_KeyPress_1(object sender,


KeyPressEventArgs e)

Page | 46
CS6004NA Application Development

{
e.Handled = !(char.IsLetter(e.KeyChar) || e.KeyChar ==
(char)Keys.Back);
}

}
}

VisitorEntryDetail.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MuseumMgntSystem
{
public partial class VisitorEntryDetail : Form
{
//repository class has all the logic to save and retrieve data.
//making a object of visitorRepository class.
public VisitorRepository _visitorRepository = new VisitorRepository();
//making object of BindingSource clss to store visitor data.
public BindingSource _visitorBindingSource = new BindingSource();
public VisitorEntryDetail()
{
InitializeComponent();
}

private void VisitorDetail_Load(object sender, EventArgs e)


{
//calls this method to get the visitor list.
retrievePictureBox_Click(sender, e);

private void pictureBox2_Click(object sender, EventArgs e)


{
this.Close();
}

private void addVisitorDetailPictureBox_Click(object sender, EventArgs


e)
{
//step 1: create object of visitorRegisterForm
VisitorEntry visitorEntry = new VisitorEntry();
visitorEntry.MaximizeBox = false;
//step 2: open the form in dialog box and store the result.
var result = visitorEntry.ShowDialog(this);
//step 3: check if user has pressed OK button
if (result == DialogResult.OK)
{
//store the data from dialog box to a variable.
var newVisitor = visitorEntry.Visitor;

Page | 47
CS6004NA Application Development

//generate unique id and store.


newVisitor.VisitorId = _visitorRepository.GenerateId();
//add to the grid
_visitorBindingSource.Add(newVisitor);
//save to the object state file.

_visitorRepository.SaveVisitors((List<Visitor>)_visitorBindingSource.DataSource
);

}
}

private void importFromCSVPictureBox_Click(object sender, EventArgs e)


{
//step 1: create an instance of windows default open dialog box.
var dialog = new OpenFileDialog();
//step 2: set filter so that it shows only csv files.
dialog.Filter = "CSV files|*.csv";

//step 3: open the dialog box


var result = dialog.ShowDialog();

//check if user has clicked OK.


if (result == System.Windows.Forms.DialogResult.OK)
{
//Step 1: read all the lines in the csv file
var csvString = File.ReadAllText(dialog.FileName);
//Step 2: Pass the csvString to ReadFromCSV method from
_visitorRepository class
//Step 3: Save the value to the binding source. (Binding Source
is used by our grid).
_visitorBindingSource.DataSource =
_visitorRepository.ReadFromCSV(csvString);
}
}

private void exportToCSVPictureBox_Click(object sender, EventArgs e)


{
//step 1: create an instance of windows default save dialog box.
var dialog = new SaveFileDialog();
//step 2: set filter so that the file can be saved with extenstion
.csv.
dialog.Filter = "CSV File|*.csv";
dialog.AddExtension = true;
//step 3: open the save dialog box
var result = dialog.ShowDialog();

if (result == System.Windows.Forms.DialogResult.OK)
{
//export filename and our data list to the ExportToCSV class.

_visitorRepository.ExportToCSV((List<Visitor>)_visitorBindingSource.DataSource,
dialog.FileName);
}
}

private void savePictureBox_Click(object sender, EventArgs e)


{

_visitorRepository.SaveVisitors((List<Visitor>)_visitorBindingSource.DataSource
);

Page | 48
CS6004NA Application Development

private void retrievePictureBox_Click(object sender, EventArgs e)


{
//Step 1: Get visitor Data from Getvisitors method of
_visitorRepository class.
//Step 2: Store it in the _visitorBindingSource.DataSource
_visitorBindingSource.DataSource = _visitorRepository.GetVisitor();
//click on Getvisitors and press f12 to navigate to the function

//if set to true creates a new object if the list is empty.


_visitorBindingSource.AllowNew = false;

//display data in the binding source in the grid.


//assign the list to the grid.
visitorListGridView.DataSource = _visitorBindingSource;
//making the grid readonly.
visitorListGridView.ReadOnly = true;
}

private void sortPictureBox_Click(object sender, EventArgs e)


{
_visitorBindingSource.DataSource =
_visitorRepository.SortUsingTotalMinutes();

//refresh the grid to view the output.


visitorListGridView.Refresh();
}

}
}

VisitorRepository.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MuseumMgntSystem
{

Page | 49
CS6004NA Application Development

public class VisitorRepository


{
private List<Visitor> _visitorList = new List<Visitor>();
//file location to save object state. It is path of {project location}\bin\Debug
private string filePath =
Path.GetDirectoryName(Application.ExecutablePath);

//start: private methods of this class

//gets object data from file location and converts to c# list.


private void DeSerializeVisitorData()
{
try
{
//step 1: check if file exists
if (File.Exists(filePath + @"\visitorDetails.dat"))
{
//step 2 : opens a stream to open the file
Stream stream = File.Open(filePath + @"\visitorDetails.dat",
FileMode.Open);

//step 3: check if file is null or emtpy.


if (stream != null && stream.Length > 0)
{
//BinaryFormatter class has method to convert .dat file to a c#
list. i.e. deserialization.
BinaryFormatter binaryFormatter = new BinaryFormatter();

//Step 4: Convert object state to c# list.


_visitorList =
(List<Visitor>)binaryFormatter.Deserialize(stream);

Page | 50
CS6004NA Application Development

}
//step 5: close the stream. after opening a stream it should always
be closed.
stream.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("Cannot get the data right now. Please visit
later");
}
}

//saves c# list object, converts to object data and saves in the file location.

private void SerializeVisitorData(List<Visitor> visitors)


{

//step 1: create a new file/ opens the file if it already exisits.


Stream str = File.Open(filePath + @"\visitorDetails.dat",
FileMode.Create);
//BinaryFormatter class has method to convert c# list to .dat file. i.e.
serialization.
BinaryFormatter bF = new BinaryFormatter();
//step 2: convert c# list to .dat file.
bF.Serialize(str, visitors);
//step 3: writes to the file.
str.Flush();
//step 4: close the stream.
str.Close();

Page | 51
CS6004NA Application Development

MessageBox.Show("Visitor details saved successfuly", "Saved Data",


MessageBoxButtons.OK, MessageBoxIcon.Information);
}

//end: private methods of this class

//start: public methods of this class. only these methods can be accessed
by other classes

//read from a csv file and conver it to c# object.


public List<Visitor> ReadFromCSV(string csvString)
{
var visitorList = new List<Visitor>();
try
{
//1st row contains property name so skipping the first row.
var lines = csvString.Split(new char[] { '\n' },
StringSplitOptions.RemoveEmptyEntries).Skip(1);

foreach (var item in lines)


{
var values = item.Split(',');
var visitor = new Visitor();
visitor.VisitorId = Convert.ToInt32(values[0]);
visitor.Date = Convert.ToDateTime(values[1]);
visitor.Day = Convert.ToString(values[2]);
visitor.CardName = Convert.ToString(values[3]);
visitor.InTime = Convert.ToDateTime(values[4]).TimeOfDay;
visitor.OutTime = Convert.ToDateTime(values[5]).TimeOfDay;

Page | 52
CS6004NA Application Development

visitor.TotalMinutes = Convert.ToDouble(values[6]);
visitorList.Add(visitor);
}
_visitorList = visitorList;

}
catch (Exception ex)
{
MessageBox.Show("Not able to save the data", "Error Saving data",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return visitorList;

public void ExportToCSV(List<Visitor> visitors, string filePath)


{
try
{
if (visitors.Count > 0)
{
var propList = visitors[0].GetType().GetProperties().Select(prop =>
prop.Name).ToList();
//TextWriter is used to create outputand streamWriter is used to
read file location

using (TextWriter TW = new StreamWriter(filePath, append: true))


{
//writes header
foreach (var prop in propList)
{

Page | 53
CS6004NA Application Development

TW.Write(prop.ToString() + ",");
}
TW.WriteLine();
//writes values
foreach (var val in visitors)
{
foreach (PropertyInfo prop in val.GetType().GetProperties())
{
TW.Write(prop.GetValue(val, null).ToString() + ",");
}
TW.WriteLine();

}
}
MessageBox.Show("Visitor details saved successfuly", "Saved
Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
Process.Start(filePath);
}
}
catch (Exception ex)
{
MessageBox.Show("Not able to save the data", "Error Saving data",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}

public List<Visitor> GetVisitor()


{
//step 1: get data from the file.
DeSerializeVisitorData();

Page | 54
CS6004NA Application Development

//check if it is null or empty.


if (_visitorList != null && _visitorList.Count > 0)
{
return _visitorList;
}
else
{
_visitorList = new List<Visitor>();
return _visitorList;
}

//accepts list of visitor and serializes the data to save as a object state.
public void SaveVisitors(List<Visitor> visitors)
{
//call this method to save the file.
SerializeVisitorData(visitors);
}

//gets the latest identity id.


public int GenerateId()
{
int id = 0;
//checks if list is null or empty
if (_visitorList != null && _visitorList.Count > 0)
{
id = _visitorList.Max(a => a.VisitorId);
}

Page | 55
CS6004NA Application Development

return id + 1;
}
public List<Visitor> SortUsingTotalMinutes()
{
for (int i = 0; i < _visitorList.Count; i++)
{
for (int j = 0; j < _visitorList.Count - 1; j++)
{
var val1 = Convert.ToInt32(_visitorList[j].TotalMinutes);
var val2 = Convert.ToInt32(_visitorList[j + 1].TotalMinutes);
if (val1 > val2)
{
var temp = _visitorList[j + 1];
_visitorList[j + 1] = _visitorList[j];
_visitorList[j] = temp;
}
}
}
return _visitorList;
}
public List<Visitor> GetWeeksData()
{
DeSerializeVisitorData();
if (_visitorList != null && _visitorList.Count > 0)
{
//set to start of week i.e Monday of current week.
var startOfWeek =
DateTime.Now.AddDays(((int)DateTime.Now.DayOfWeek * -1) + 1);
//set time as 10:00:00
startOfWeek = new DateTime(startOfWeek.Year,
startOfWeek.Month, startOfWeek.Day, 00, 0, 0);

Page | 56
CS6004NA Application Development

//set end of week i,e Friday of current we


var endOfWeek = startOfWeek.AddDays(4);
//set time as 17:00:00
endOfWeek = new DateTime(endOfWeek.Year, endOfWeek.Month,
endOfWeek.Day, 18, 0, 0);
//where rentDetail.Date >= startOfWeek
// && rentDetail.Date <= endOfWeek
//get only this weeks data

var weeklyData = (from visitor in _visitorList


where visitor.Date >= startOfWeek
&& visitor.Date <= endOfWeek
group visitor by visitor.Date into grp //groups data by date.
select new Visitor
{
Date = grp.Max(a => a.Date), //gets maximum value of
date selected.
Count = grp.Count(),
TotalMinutes = grp.Sum(a => a.TotalMinutes) //get
sum of total hours on that day.
}).OrderByDescending(a => a.Count).ToList(); //orders
the data in descending order and returns a list.
return weeklyData;
}
else
{
_visitorList = new List<Visitor>();
return _visitorList;
}
}
public List<Visitor> GetTodayData()

Page | 57
CS6004NA Application Development

{
DeSerializeVisitorData();
if (_visitorList != null && _visitorList.Count > 0)
{

DateTime thisDay = DateTime.Today;


var dailyData = (from visitor in _visitorList
where visitor.Date == thisDay

group visitor by visitor.Date into grp //groups data by date.


select new Visitor
{
Date = grp.Max(a => a.Date), //gets maximum value of
date selected.
Count = grp.Count(),//to count the total number of
visitor
TotalMinutes = grp.Sum(a => a.TotalMinutes) //get
sum of total hours on that day.
}).OrderByDescending(a => a.Count).ToList(); //orders
the data in descending order and returns a list.
return dailyData;

else
{
_visitorList = new List<Visitor>();
return _visitorList;
}
}

Page | 58
CS6004NA Application Development

}
}
WeeklyReportChart.cs
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;

namespace MuseumMgntSystem
{
public partial class weeklyReportChart : Form
{
private VisitorRepository _visitorRepository = new VisitorRepository();
private List<Visitor> _visitorList = new List<Visitor>();
public weeklyReportChart()
{
InitializeComponent();
}

private void WeeklyReportChart_Load(object sender, EventArgs e)


{
LoadVisitorDetail();
weeklyGrid.Visible = false;
visitorDetailChart.Visible = false;
weeklyGrid.ReadOnly = true;
}
private void LoadVisitorDetail()
{
_visitorList = _visitorRepository.GetWeeksData();
weeklyGrid.ReadOnly = true;

}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.Close();
}

private void displayChartButton_Click(object sender, EventArgs e)


{
visitorDetailChart.Visible = true;
weeklyGrid.Visible = false;
foreach (var visitor in _visitorList)
{
visitorDetailChart.Series["Total
Minutes"].Points.AddXY(visitor.Date.DayOfWeek.ToString(),
visitor.TotalMinutes.ToString());
}
displayChartButton.Enabled = false;
}

private void displayTableButton_Click(object sender, EventArgs e)


{

Page | 59
CS6004NA Application Development

weeklyGrid.Visible = true;
visitorDetailChart.Visible = false;
foreach (var visitor in _visitorList)
{
var dayName = visitor.Date.DayOfWeek.ToString();
var totalMinutes = visitor.TotalMinutes.ToString();
var totalCount = visitor.Count.ToString();
this.weeklyGrid.Rows.Add(totalCount, dayName, totalMinutes);
}
displayTableButton.Enabled = false;
}
}
}

DailyChartReport.cs
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;

namespace MuseumMgntSystem
{
public partial class DailyReportChart : Form
{
private VisitorRepository _visitorRepository = new VisitorRepository();
private List<Visitor> _visitorList = new List<Visitor>();
public DailyReportChart()
{
InitializeComponent();
}

private void LoadVisitorDetail()


{
_visitorList = _visitorRepository.GetTodayData();

private void DailyReportChart_Load_1(object sender, EventArgs e)


{
LoadVisitorDetail();
dailyGrid.Visible = false;
visitorDailyDetailChart.Visible = false;
dailyGrid.ReadOnly = true;

private void displayChartButton_Click(object sender, EventArgs e)


{

dailyGrid.Visible = false;
visitorDailyDetailChart.Visible = true;
foreach (var visitor in _visitorList)
{

Page | 60
CS6004NA Application Development

visitorDailyDetailChart.Series["Total
Minutes"].Points.AddXY(visitor.Date.DayOfWeek.ToString(),
visitor.TotalMinutes.ToString());
}
displayChartButton.Enabled = false;

private void displayTableButton_Click(object sender, EventArgs e)


{
visitorDailyDetailChart.Visible = false;
dailyGrid.Visible = true;
foreach (var visitor in _visitorList)
{
var dayName = visitor.Date.DayOfWeek.ToString();
var totalMinutes = visitor.TotalMinutes.ToString();
var totalCount = visitor.Count.ToString();
this.dailyGrid.Rows.Add(totalCount, dayName, totalMinutes);
}
displayTableButton.Enabled = false;

private void pictureBox1_Click(object sender, EventArgs e)


{
this.Close();
}
}
}

AddVisitorDetails.cs
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;

namespace MuseumMgntSystem
{

public partial class AddVisitorDetails : Form


{
public VisitorRepository _visitorRepository = new VisitorRepository();
public BindingSource _visitorBindingSource = new BindingSource();
public AddVisitorDetails()
{
InitializeComponent();
}

private void AddVisitorDetails_Load(object sender, EventArgs e)


{
GetVisitorData(sender, e);
}
private void GetVisitorData(object sender, EventArgs e)
{

Page | 61
CS6004NA Application Development

//to display in grid


//it get's visitor data from visitorRepository class.
_visitorBindingSource.DataSource = _visitorRepository.GetVisitor();

//if set to true creates a new object if the list is empty.


_visitorBindingSource.AllowNew = false;

visitorComboBox.DataSource = _visitorBindingSource;
visitorComboBox.DisplayMember = "CardName";
visitorComboBox.ValueMember = "CardName";
}
public VisitorDetail VisitorDetail
{
get
{
var visitorDetail = new VisitorDetail();
visitorDetail.CardName =
Convert.ToString(visitorComboBox.SelectedValue);
visitorDetail.LastName = lastNameTextBox.Text;
visitorDetail.Email = emailTextBox.Text;
visitorDetail.Contact = contactNumberTextBox.Text;
visitorDetail.Occupation = occupationTextBox.Text;
return visitorDetail;
}
}

private void firstNameTextBox_KeyPress(object sender, KeyPressEventArgs


e)
{
checker(sender, e);
//e.Handled = !(char.IsLetter(e.KeyChar) || e.KeyChar ==
(char)Keys.Back);
}

private void emailTextBox_Validating(object sender, CancelEventArgs e)


{
System.Text.RegularExpressions.Regex rEmail = new
System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-
9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");

if (emailTextBox.Text.Length > 0 && emailTextBox.Text.Trim().Length


!= 0)
{
if (!rEmail.IsMatch(emailTextBox.Text.Trim()))
{
MessageBox.Show("Please enter a valid email address.",
"Invalid Email", MessageBoxButtons.OK, MessageBoxIcon.Warning);
emailTextBox.SelectAll();
e.Cancel = true;
}
}
}

private void contactNumberTextBox_KeyPress(object sender,


KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
(e.KeyChar != '+') && (e.KeyChar != '-'))
{
e.Handled = true;
}
}

Page | 62
CS6004NA Application Development

public void checker(object sender, KeyPressEventArgs e)


{
e.Handled = !(char.IsLetter(e.KeyChar) || e.KeyChar ==
(char)Keys.Back);
}

private void occupationTextBox_KeyPress(object sender,


KeyPressEventArgs e)
{
checker(sender, e);
}

}
}

Page | 63

You might also like