// reads visitors entry from csv file
        // for initializing the entry while loading the file
        public void readEntryCSV(string filePath)
        {
            try
            {
                using (var reader = new StreamReader(filePath))
                {
                    if (!reader.EndOfStream)
                    {
                        reader.ReadLine();
                    }
                    while (!reader.EndOfStream)
                    {
                        var line   = reader.ReadLine();
                        var values = line.Split(',');

                        VisitorsEntry visitorEntry = new VisitorsEntry(Convert.ToDateTime(values[1]), values[2].ToString(), TimeSpan.Parse(values[3]), TimeSpan.Parse(values[4]), Convert.ToDouble(values[5]));
                        visitorEntry.VisitorId = Int32.Parse(values[0]);

                        if (visitorController.getVisitor(visitorEntry.VisitorId) != null)
                        {
                            this.VisitorEntryList.Add(visitorEntry);
                        }
                    }
                }
            }
            catch (IOException)
            {
                Console.WriteLine("File not found : " + filePath);
            }
        }
Esempio n. 2
0
        private void entry_btn_Click(object sender, EventArgs e)
        {
            entry_error_label.Visible = true;
            if (this.check_entry_input())
            {
                int      visitor_id = Int32.Parse(visitor_id_field.Text);
                TimeSpan entry_time = DateTime.Now.TimeOfDay;
                String   day        = DateTime.Now.DayOfWeek.ToString();
                if (entry_time.CompareTo(new TimeSpan(10, 00, 00)) != -1 && entry_time.CompareTo(new TimeSpan(17, 00, 00)) == -1 &&
                    day != "Sunday" && day != "Saturday")
                {
                    VisitorsEntry entry_record = new VisitorsEntry(visitor_id, day, CurrentDate, entry_time);
                    if (!File.Exists(visitor_entry_file))
                    {
                        // create table row head when creating new csv file
                        entryController.initiateEntryData(visitor_entry_file);
                    }

                    //Appends item to the list
                    VisitorEntryList.Add(entry_record);

                    //adds to the csv file
                    //does not append updates the entire csv file
                    entryController.writeEntryData(entry_record, visitor_entry_file);

                    //Adds row to the table
                    this.addVisitorEntry(entry_record);
                }
            }
        }
        // writing new entries to the entry csv file
        public void writeEntryData(VisitorsEntry visitorEntry, string filePath)
        {
            string desktop_path = filePath;

            using (var writer = new StreamWriter(desktop_path, append: true))
            {
                var line = string.Format("{0}, {1}, {2}, {3}, {4}, {5}", visitorEntry.VisitorId, visitorEntry.EntryDate, visitorEntry.Day, visitorEntry.EntryTime, visitorEntry.ExitTime, visitorEntry.Duration);

                writer.WriteLine(line);
                writer.Flush();
            }
        }
Esempio n. 4
0
        public void addVisitorEntry(VisitorsEntry entry)
        {
            // refrences to the visitor from the visitors list
            Visitor visitor = visitorController.getVisitor(entry.VisitorId);

            if (visitor != null)
            {
                // check if the data is of entry
                if (entry.ExitTime.ToString() != "00:00:00")
                {
                    this.visitor_entry_table.Rows.Add(entry.VisitorId, entry.Day,
                                                      visitor.FirstName + " " + visitor.LastName, formatDate(entry.EntryTime), formatDate(entry.ExitTime),
                                                      Convert.ToDecimal(string.Format("{0:F3}", entry.Duration)).ToString() + " min");
                }
                // if the data is of exit
                else
                {
                    this.visitor_entry_table.Rows.Add(entry.VisitorId, entry.Day, visitor.FirstName + " " + visitor.LastName, entry.EntryTime, "  --:--:--  ", "  --:--:--  ");
                }
            }
        }
Esempio n. 5
0
        private void visitor_entry_table_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            // get entry time of the selected row
            TimeSpan givenEntryTime = TimeSpan.Parse(visitor_entry_table.Rows[e.RowIndex].Cells[3].Value.ToString());

            // if there is only one visitor in the list
            if (VisitorEntryList.Count == 1)
            {
                VisitorsEntry entry = VisitorEntryList[0];
                entry.ExitTime = DateTime.Now.TimeOfDay;

                entry.Duration = entry.ExitTime.Subtract(entry.EntryTime).TotalMinutes;

                // updating the visitor list
                VisitorEntryList.Remove(entry);
                VisitorEntryList.Add(entry);

                // updating the csv file
                updateVisitorEntryCsv();
                refreshVisitorEntryTable();
            }
            // if selected row is not empty or null
            else if (e.RowIndex > -1 && visitor_entry_table.Rows[e.RowIndex].Cells[0] != null)
            {
                // user binary search to retrive visitor by entry time
                VisitorsEntry visitorEntry = entryController.getEntryByDate(givenEntryTime);
                // update the list and csv file after visitor exits
                if (visitorEntry != null)
                {
                    visitorEntry.ExitTime = DateTime.Now.TimeOfDay;

                    visitorEntry.Duration = visitorEntry.ExitTime.Subtract(visitorEntry.EntryTime).TotalMinutes;

                    VisitorEntryList.Remove(visitorEntry);
                    VisitorEntryList.Add(visitorEntry);
                    updateVisitorEntryCsv();
                }
                refreshVisitorEntryTable();
            }
        }