private void WriteCheckoutDataToFile(List <VisitorsInformation> visitorList)
        {
            if (File.Exists("CheckoutsInformation.csv"))
            {
                using (Stream stream = new FileStream("CheckoutsInformation.csv", FileMode.Open, FileAccess.ReadWrite))
                {
                    var cs = new CsvChecker <VisitorsInformation>()
                    {
                        UseTextQualifier = true
                    };
                    cs.AppendToFile(stream, visitorList, "CheckoutsInformation.csv");
                }
            }
            else
            {
                using (Stream stream = new FileStream("CheckoutsInformation.csv", FileMode.Create, FileAccess.Write))
                {
                    var cs = new CsvChecker <VisitorsInformation>
                    {
                        UseTextQualifier = true
                    };

                    cs.WriteToFile(stream, visitorList);
                }
            }
        }
        private void BtnCsvInput_Click(object sender, EventArgs e)
        {
            DialogResult result = csvOpenFileDialog.ShowDialog();
            List <VisitorsInformation> visitorList = new List <VisitorsInformation>();

            if (result == DialogResult.OK)
            {
                using (var stream = new FileStream(csvOpenFileDialog.FileName, FileMode.Open, FileAccess.Read))
                {
                    var cs = new CsvChecker <VisitorsInformation>()
                    {
                        UseTextQualifier = true
                    };

                    visitorList = cs.ReadFromFile(stream);
                    WriteCheckInDataToFile(visitorList);
                }
            }
            DispInputGridView.Hide();
            if (visitorList.Count > 0)
            {
                BindingList <VisitorsInformation> bindingList = new BindingList <VisitorsInformation>(visitorList);
                BindingSource source = new BindingSource(bindingList, null);
                DispInputGridView.DataSource = source;
                DispInputGridView.Show();
            }
        }
        private void BtnWeeklyReport_Click(object sender, EventArgs e)
        {
            List <VisitorsInformation> list = new List <VisitorsInformation>();

            using (Stream stream = new FileStream("CheckoutsInformation.csv", FileMode.Open, FileAccess.Read))
            {
                CsvChecker <VisitorsInformation> cs = new CsvChecker <VisitorsInformation>()
                {
                    UseTextQualifier = true,
                };
                list = cs.ReadFromFile(stream);
            }

            var dateFrom = weeklyDatePicker.Value.Date;
            int dayindex = (int)dateFrom.DayOfWeek;
            int diff     = 5 - dayindex;
            var dateTo   = dateFrom.AddDays(diff);


            List <VisitorsInformation> filteredList = new List <VisitorsInformation>();

            foreach (VisitorsInformation v in list)
            {
                var date = DateTime.ParseExact(v.EntryDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);

                if (date >= dateFrom && date <= dateTo)
                {
                    DateTime outTime = DateTime.Parse(v.CheckOutTime);
                    DateTime inTime  = DateTime.Parse(v.CheckInTime);
                    TimeSpan diffT   = (outTime - inTime);
                    v.TotalDuration = Math.Round(diffT.TotalMinutes, 2);
                    v.Day           = date.DayOfWeek.ToString();
                    filteredList.Add(v);
                }
            }

            List <ReportsWeekly> weekReport = GetWeekReport(filteredList);

            reportChart.Series.Clear();
            reportChart.Series.Add("Total Time Spent (In Minutes)");

            foreach (ReportsWeekly report in weekReport)
            {
                reportChart.Series["Total Time Spent (In Minutes)"].Points.AddXY(report.Day, report.TotalTimeSpent);
            }
            reportChart.Show();

            MuseumManagementSystem.SortingAlgorithm sort        = new MuseumManagementSystem.SortingAlgorithm();
            BindingList <ReportsWeekly>             bindingList = new BindingList <ReportsWeekly>(sort.QuickSortByTotalVisitor(weekReport));
            BindingSource source = new BindingSource(bindingList, null);

            dispReportGridView.DataSource = source;
            dispReportGridView.Show();
        }
        private void BtnDailyReport_Click(object sender, EventArgs e)
        {
            List <VisitorsInformation> list = new List <VisitorsInformation>();

            using (Stream stream = new FileStream("CheckoutsInformation.csv", FileMode.Open, FileAccess.Read))
            {
                CsvChecker <VisitorsInformation> cs = new CsvChecker <VisitorsInformation>()
                {
                    UseTextQualifier = true,
                };
                list = cs.ReadFromFile(stream);
            }

            var date = dailyDatePicker.Value.Date.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
            List <VisitorsInformation> filteredList = new List <VisitorsInformation>();

            foreach (VisitorsInformation v in list)
            {
                if (v.EntryDate.Equals(date))
                {
                    DateTime outTime = DateTime.Parse(v.CheckOutTime);
                    DateTime inTime  = DateTime.Parse(v.CheckInTime);
                    TimeSpan diff    = (outTime - inTime);
                    v.TotalDuration = Math.Round(diff.TotalMinutes, 2);
                    v.Day           = inTime.DayOfWeek.ToString();
                    filteredList.Add(v);
                }
            }

            string day = dailyDatePicker.Value.DayOfWeek.ToString();
            List <ReportsWeekly> weekReport        = GetWeekReport(filteredList);
            List <ReportsWeekly> finalWeeklyReport = new List <ReportsWeekly>();

            finalWeeklyReport.Add(weekReport.Find(a => a.Day.Equals(day)));

            BindingList <ReportsWeekly> bindingList = new BindingList <ReportsWeekly>(finalWeeklyReport);
            BindingSource source = new BindingSource(bindingList, null);

            dispReportGridView.DataSource = source;
            dispReportGridView.Show();
            reportChart.Hide();
        }
        private void NewEntryBtn_Click(object sender, EventArgs e)
        {
            lblMnlInput.Show();
            lblMnlInput.Text = "Manual Input";
            long ID = Int64.Parse(tempVisitorID.Text);

            visitorID.Text     = (ID + 1).ToString();
            tempVisitorID.Text = visitorID.Text;
            ResetVisitorsEntryForm();
            lblMainMsg.Hide();
            dispReportPanel.Hide();
            newVisitorEntryPanel.Show();
            errFirstName.Visible    = false;
            errLastName.Visible     = false;
            errOccupation.Visible   = false;
            errContactNo.Visible    = false;
            errEmailAddress.Visible = false;
            errAddress.Visible      = false;
            btnSave.Text            = "Check In";
            TxtInputPanel.Show();
            MainGrpBox.Text = "Register Visitors";

            if (File.Exists("CheckinsInformation.csv"))
            {
                List <VisitorsInformation> list = new List <VisitorsInformation>();

                using (Stream stream = new FileStream("CheckinsInformation.csv", FileMode.Open, FileAccess.Read))
                {
                    CsvChecker <VisitorsInformation> cs = new CsvChecker <VisitorsInformation>()
                    {
                        UseTextQualifier = true,
                    };
                    list = cs.ReadFromFile(stream);
                }

                BindingList <VisitorsInformation> bindingList = new BindingList <VisitorsInformation>(list);
                BindingSource source = new BindingSource(bindingList, null);
                DispInputGridView.DataSource = source;
                DispInputGridView.Show();
            }
        }
        private void CSVSearch(string searchValue)
        {
            List <VisitorsInformation> searchedData = new List <VisitorsInformation>();

            if (File.Exists("CheckinsInformation.csv"))
            {
                using (Stream stream = new FileStream("CheckinsInformation.csv", FileMode.Open, FileAccess.Read))
                {
                    CsvChecker <VisitorsInformation> cs = new CsvChecker <VisitorsInformation>()
                    {
                        UseTextQualifier = true,
                    };

                    searchedData = cs.SearchInFile(stream, searchValue);
                }
            }
            else
            {
                lblMainMsg.Text = "Visitor Not Found";
                lblMainMsg.Show();
            }

            bool   visitorFound = false;
            string dateTody     = dateToday.Text;

            foreach (VisitorsInformation v in searchedData)
            {
                var abc = v.EntryDate;
                if (v.EntryDate.Equals(dateTody))
                {
                    visitorFound = true;

                    visitorID.Text         = v.ID.ToString();
                    txtFirstName.Text      = v.FirstName;
                    txtLastName.Text       = v.LastName;
                    txtContactNo.Text      = v.ContactNo.ToString();
                    txtAddress.Text        = v.Address;
                    txtOccupation.Text     = v.Occupation;
                    txtEmailAddr.Text      = v.EmailAddress;
                    CheckInTimePicker.Text = v.CheckInTime;

                    txtFirstName.Enabled      = false;
                    txtLastName.Enabled       = false;
                    txtContactNo.Enabled      = false;
                    txtAddress.Enabled        = false;
                    txtEmailAddr.Enabled      = false;
                    txtOccupation.Enabled     = false;
                    CheckInTimePicker.Enabled = false;

                    lblOutTime.Show();
                    CheckOutTimepicker.Show();
                    newVisitorEntryPanel.Show();
                    lblMainMsg.Hide();
                    btnClear.Visible = false;
                }
            }

            if (!visitorFound)
            {
                lblMainMsg.Text = "Visitor Not Found";
                lblMainMsg.Show();
            }
        }