Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
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();
            }
        }