-
-
Save anonymous/a325acbff5091d22770b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace excelCsvReader | |
{ | |
class WorkSpan | |
{ | |
public string PersonName { get; set; } | |
public DateTime DateStart { get; set; } | |
public DateTime DateEnd { get; set; } | |
public WorkSpan(string personName, DateTime dateStart, DateTime dateEnd) | |
{ | |
this.DateStart = dateStart; | |
this.PersonName = personName; | |
this.DateEnd = dateEnd; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PersonEntered | |
{ | |
public string PersonName { get; set; } | |
public DateTime DateOfEntry { get; set; } | |
public DoorType DoorEntered { get; set; } | |
public PersonEntered(string name, DateTime dateOfEntry, DoorType enteredInto) | |
{ | |
this.PersonName = name; | |
this.DateOfEntry = dateOfEntry; | |
this.DoorEntered = enteredInto; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Windows.Forms; | |
using System.IO; | |
namespace excelCsvReader | |
{ | |
public partial class Form1 : Form | |
{ | |
public const string RearEntranceDoor = "AO2 - Rear Entrance"; | |
public const string ExteriorMainFloorDoor = "B12 - Exterior Main Floor Man Trap"; | |
public const string InteriorMainFloorDoor = "B12 - Interior Main Floor Man Trap"; | |
public const string RearBreakRoomDoor = "C13 - Rear Break Room Door"; | |
public const string ExteriorBasementDoor = "B02 - Exterior Basement Man Trap"; | |
public const string InteriorBasementDoor = "B02 - Interior Basement Man Trap"; | |
public const string ManagedServicesDoor = "D01 - Managed Services Main door"; | |
public const string ManagedServiceBigDoor = "D01 - Managed Services Big Door"; | |
TimeSpan midnightShift = TimeSpan.Parse("20:00:00"); | |
TimeSpan midnightShift2 = TimeSpan.Parse("07:00:00"); | |
TimeSpan middayShift = TimeSpan.Parse("09:30:00"); | |
TimeSpan middayShift2 = TimeSpan.Parse("20:30:00"); | |
TimeSpan middayShift3 = TimeSpan.Parse("09:30:00"); | |
TimeSpan middayShift4 = TimeSpan.Parse("21:30:00"); | |
TimeSpan morningShift = TimeSpan.Parse("07:00:00"); | |
TimeSpan morningShift2 = TimeSpan.Parse("19:00:00"); | |
List<PersonEntered> peopleEntering; | |
List<WorkSpan> workSpans; | |
public Form1() | |
{ | |
InitializeComponent(); | |
TurnOffLabelsandPanels(); | |
peopleEntering = new List<PersonEntered>(); | |
workSpans = new List<WorkSpan>(); | |
} | |
private void csvButton_Click(object sender, EventArgs e) | |
{ | |
string delimiter = ","; | |
string tablename = "Csvfile"; | |
DataSet dataset = new DataSet(); | |
OpenFileDialog csvOpenFileDialog1 = new OpenFileDialog(); | |
csvOpenFileDialog1.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*"; | |
csvOpenFileDialog1.FilterIndex = 1; | |
if (csvOpenFileDialog1.ShowDialog() == DialogResult.OK) | |
{ | |
if (MessageBox.Show("Are you sure you want to import the data from \n " + csvOpenFileDialog1.FileName + "?", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes) | |
{ | |
filename = csvOpenFileDialog1.FileName; | |
StreamReader sr = new StreamReader(filename); | |
string csv = File.ReadAllText(csvOpenFileDialog1.FileName); | |
string allData = sr.ReadToEnd(); | |
string[] rows = allData.Split("\n".ToCharArray()); | |
bool header = true; | |
foreach (string r in rows) | |
{ | |
string[] items = r.Split(delimiter.ToCharArray()); | |
if (header) | |
{ | |
dataset.Tables.Add(tablename); | |
dataset.Tables[tablename].Columns.Add(items[0]);//Sequence\\ | |
dataset.Tables[tablename].Columns.Add(items[1]);//Date and Time\\ | |
dataset.Tables[tablename].Columns.Add(items[2]);//Event message\\ | |
dataset.Tables[tablename].Columns.Add(items[3]);//Event number\\ | |
dataset.Tables[tablename].Columns.Add(items[4]);//Object #1\\ | |
dataset.Tables[tablename].Columns.Add(items[5]);//doors\\ | |
dataset.Tables[tablename].Columns.Add(items[6]);//Object #2\\ | |
dataset.Tables[tablename].Columns.Add(items[7]);//Employee name\\ | |
dataset.Tables[tablename].Columns.Add(items[8]);//Object #3\\ | |
dataset.Tables[tablename].Columns.Add(items[9]);//Description #3\\ | |
dataset.Tables[tablename].Columns.Add(items[10]);//Object #4\\ | |
dataset.Tables[tablename].Columns.Add(items[11]);//Description #4\\ | |
dataset.Tables[tablename].Columns.Add(items[12]);//keycard\\ | |
header = false; | |
} | |
else | |
{ | |
if (!String.IsNullOrEmpty(items[0])) | |
{ | |
dataset.Tables[tablename].Rows.Add(items); | |
} | |
} | |
foreach (DataRow dr in dataset.Tables[0].Rows) | |
{ | |
string dateAndTime = dr["Date and Time"].ToString(); | |
string personName = dr["Description #2"].ToString(); | |
string doorType = dr["Description #1"].ToString(); | |
DateTime dateEntered = Convert.ToDateTime(dateAndTime); | |
DoorType doorTypeEnum; | |
bool personExists = false; | |
foreach (object name in listboxOfNames.Items) | |
{ | |
if (name.ToString() == personName) | |
{ | |
personExists = true; | |
break; | |
} | |
} | |
if (!personExists) | |
{ | |
listboxOfNames.Items.Add(personName); | |
} | |
switch (doorType) | |
{ | |
case "A02 - Rear Entrance": | |
doorTypeEnum = DoorType.RearEntranceDoor; | |
break; | |
case "B12 - Exterior Main Floor Man Trap": | |
doorTypeEnum = DoorType.ExteriorMainFloorDoor; | |
break; | |
case "B12 - Interior Main Floor Man Trap": | |
doorTypeEnum = DoorType.InteriorMainFloorDoor; | |
break; | |
case "C13 - Rear Break Room Door": | |
doorTypeEnum = DoorType.RearBreakRoomDoor; | |
break; | |
case "B02 - Exterior Basement Man Trap": | |
doorTypeEnum = DoorType.ExteriorBasementDoor; | |
break; | |
case "B02 - Interior Basement Man Trap": | |
doorTypeEnum = DoorType.InteriorBasementDoor; | |
break; | |
case "D01 - Managed Services Main door": | |
doorTypeEnum = DoorType.ManagedServicesDoor; | |
break; | |
case "D01 - Managed Services Big Door": | |
doorTypeEnum = DoorType.ManagedServicesBigDoor; | |
break; | |
default: | |
doorTypeEnum = DoorType.None; | |
break; | |
} | |
peopleEntering.Add(new PersonEntered(personName, dateEntered, doorTypeEnum)); | |
} | |
} | |
for (int i = 0; i < peopleEntering.Count; i++) | |
{ | |
DateTime startDate = new DateTime(); | |
DateTime endDate = new DateTime(); | |
string personName = peopleEntering[i].PersonName; | |
if (peopleEntering[i].DoorEntered == DoorType.RearEntranceDoor) | |
{ | |
startDate = peopleEntering[i].DateOfEntry; | |
for (int j = i + 1; j < peopleEntering.Count; j++) | |
{ | |
if (peopleEntering[j].DoorEntered == DoorType.ExteriorBasementDoor && peopleEntering[j].PersonName == personName) | |
{ | |
endDate = peopleEntering[j].DateOfEntry; | |
} | |
} | |
} | |
workSpans.Add(new WorkSpan(personName, startDate, endDate)); | |
} | |
TurnOnLabels(); | |
this.csvGridView.DataSource = dataset.Tables[0].DefaultView; | |
MessageBox.Show(filename + " was successfully imported. \n ", "Success!", MessageBoxButtons.OK); | |
} | |
else | |
{ | |
this.Close(); | |
} | |
} | |
} | |
public string filename { get; set; } | |
private void csvGridView_CellClick(object sender, DataGridViewCellEventArgs e) | |
{ | |
int i; | |
i = csvGridView.SelectedCells[0].RowIndex; | |
csvGridView.Columns[2].Visible = false; | |
csvGridView.Columns[3].Visible = false; | |
csvGridView.Columns[4].Visible = false; | |
csvGridView.Columns[6].Visible = false; | |
csvGridView.Columns[8].Visible = false; | |
csvGridView.Columns[9].Visible = false; | |
csvGridView.Columns[10].Visible = false; | |
csvGridView.Columns[11].Visible = false; | |
CsvInfoPanel.Visible = true; | |
firstLastNameLbl.Text = csvGridView.Rows[i].Cells[7].Value.ToString(); | |
keyCardNumberLbl.Text = csvGridView.Rows[i].Cells[12].Value.ToString(); | |
timeDateEntryLbl.Text = csvGridView.Rows[i].Cells[1].Value.ToString(); | |
dateTimeDepartureLbl.Text = csvGridView.Rows[17].Cells[1].Value.ToString(); | |
DateTime startDate = Convert.ToDateTime(csvGridView.Rows[i].Cells[1].Value.ToString()); | |
DateTime endDate = Convert.ToDateTime(csvGridView.Rows[17].Cells[1].Value.ToString()); | |
TimeSpan difference = endDate - startDate; | |
string personName = csvGridView.Rows[i].Cells[0].Value.ToString(); | |
List<WorkSpan> listOfWorkSpans = new List<WorkSpan>(); | |
for (int j = 0; j < workSpans.Count; j++) | |
{ | |
if (workSpans[j].PersonName == personName) | |
{ | |
listOfWorkSpans.Add(workSpans[j]); | |
} | |
} | |
} | |
private void listboxOfNames_SelectedIndexChanged(object sender, EventArgs e) | |
{ | |
TurnOnPanel(); | |
string personName = listboxOfNames.Items[listboxOfNames.SelectedIndex].ToString(); | |
List<WorkSpan> listOfWorkSpan = new List<WorkSpan>(); | |
foreach (WorkSpan workSpan in workSpans) | |
{ | |
if (workSpan.PersonName == personName) | |
{ | |
listOfWorkSpan.Add(workSpan); | |
} | |
} | |
int b; | |
//create TimeSpan object | |
b = csvGridView.SelectedCells[0].RowIndex; | |
csvGridView.DataSource = listOfWorkSpan; | |
firstLastNameLbl.Text = csvGridView.Rows[b].Cells[0].Value.ToString(); | |
timeDateEntryLbl.Text = csvGridView.Rows[b].Cells[1].Value.ToString(); | |
dateTimeDepartureLbl.Text = csvGridView.Rows[b].Cells[2].Value.ToString(); | |
DateTime startDate = System.Convert.ToDateTime(csvGridView.Rows[b].Cells[1].Value.ToString()); | |
DateTime endDate = System.Convert.ToDateTime(csvGridView.Rows[b].Cells[2].Value.ToString()); | |
TimeSpan difference = endDate - startDate; | |
} | |
private void TurnOnLabels() | |
{ | |
csvGridView.Visible = true; | |
EmployeeNameLbl.Visible = true; | |
keycardLbl.Visible = true; | |
dateTimeEntryLbl.Visible = true; | |
dateTimeExitedLbl.Visible = true; | |
hoursClockedInLbl.Visible = true; | |
firstLastNameLbl.Visible = true; | |
keyCardNumberLbl.Visible = true; | |
timeDateEntryLbl.Visible = true; | |
dateTimeDepartureLbl.Visible = true; | |
keyedInHoursLbl.Visible = true; | |
listboxOfNames.Visible = true; | |
nameSelectionLbl.Visible = true; | |
} | |
private void TurnOnPanel() | |
{ | |
CsvInfoPanel.Visible = true; | |
EmployeeNameLbl.Visible = true; | |
dateTimeEntryLbl.Visible = true; | |
dateTimeExitedLbl.Visible = true; | |
firstLastNameLbl.Visible = true; | |
timeDateEntryLbl.Visible = true; | |
dateTimeDepartureLbl.Visible = true; | |
keycardLbl.Visible = false; | |
keyCardNumberLbl.Visible = false; | |
} | |
private void TurnOffLabelsandPanels() | |
{ | |
csvGridView.Visible = false; | |
EmployeeNameLbl.Visible = false; | |
keycardLbl.Visible = false; | |
dateTimeEntryLbl.Visible = false; | |
dateTimeExitedLbl.Visible = false; | |
hoursClockedInLbl.Visible = false; | |
firstLastNameLbl.Visible = false; | |
keyCardNumberLbl.Visible = false; | |
timeDateEntryLbl.Visible = false; | |
dateTimeDepartureLbl.Visible = false; | |
keyedInHoursLbl.Visible = false; | |
listboxOfNames.Visible = false; | |
nameSelectionLbl.Visible = false; | |
CsvInfoPanel.Visible = false; | |
} | |
private void closeButton_Click(object sender, EventArgs e) | |
{ | |
this.Close(); | |
} | |
} | |
public enum DoorType | |
{ | |
None = 0, | |
RearEntranceDoor = 1, | |
ExteriorMainFloorDoor = 2, | |
InteriorMainFloorDoor = 3, | |
RearBreakRoomDoor = 4, | |
ExteriorBasementDoor = 5, | |
InteriorBasementDoor = 6, | |
ManagedServicesDoor = 7, | |
ManagedServicesBigDoor = 8 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment