-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSelect.cs
147 lines (117 loc) · 4.69 KB
/
Select.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AttendanceSystem
{
public partial class Select : Form
{
public Select()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
/*
//Taking inputs from dropdown menu
if(comboBox1.Text==""){//empty
this.Hide();
new Select().Show();
}
if (comboBox2.Text == "") {//empty
this.Hide();
new Select().Show();
}
*/
temp.courseName = comboBox1.Text;
String camSrc = comboBox2.Text;
//MessageBox.Show("", "");
string course = temp.courseName;
int camSource = 0;
if (camSrc.Contains("Laptop"))
{
camSource = 0;
}
else if (camSrc.Contains("External"))
{
camSource = 1;
}
else camSource = 2;
//******************************************************************************************************************************************************
if (camSource == 2)
{//Taking attendance Manually
this.Close();
new Attendance().Show();
return;
}
string fileName = @"E:\Sem7\HCI\ProjAttendanceSystem\HCI\recognize_faces_video.py"; //python script to run
#region Execute python script
Process p = new Process();
p.StartInfo = new ProcessStartInfo(@"C:\Python37\python.exe", fileName)
{
Arguments = string.Format("{0} {1} {2}", fileName, course, camSource),//command line arguments
RedirectStandardOutput = true,//passing of parameters
UseShellExecute = false,
CreateNoWindow = false,//for opening facial recognition window, set it to false
};
p.Start();//runs the script
this.Close();//hides the main screen
string output = p.StandardOutput.ReadToEnd();//returns output of script
p.WaitForExit();
int ErrorResult = checkError(output);
#endregion
if (ErrorResult == -1)
{//error
return;
}
else
{//no error
string[] a = output.Split('\n');
//initializing variables
string courseName = a[0];
string totalStudents = a[1];
string totPresent = a[2];
string[] students = { "Manan", "Murtaza", "Yasir", "Imtiaz" };
string pres = "";
List<string> presStudents = new List<string>();
for (int i = 3; i < a.Length - 1; i++)
{
presStudents.Add(a[i]);//adding present students in list
}
foreach (string i in presStudents)
{
pres += i;
pres += "\n";
}
//Displaying current attendance
MessageBox.Show("CourseName:\t\t" + courseName + "\nTotal Students:\t\t" + totalStudents + "\nTotal Students Present:\t" + totPresent + "\nPresent Students:\n" + pres, "Automatic Attendance System -> Select -> Attendance");
//Saving current attendance in text file
System.IO.File.WriteAllText(@"E:\Sem7\HCI\ProjAttendanceSystem\HCI\log.txt", "CourseName:\t\t" + courseName + "\nTotal Students:\t\t" + totalStudents + "\nTotal Students Present:\t" + totPresent + "\nPresent Students:\n" + pres);
//Relaunching main screen
this.Close();
}
this.Hide();
}
public int checkError(string output)
{
if (output.Contains("-1"))
{//if an error occured during execution such as camera malfunction
MessageBox.Show("An error occurred during execution\nKindly check whether the camera is working properly", "Automatic Attendance System -> Error");
return -1;
}
return 0;//if everything runs smoothly without any error
}
private void Select_FormClosing(object sender, FormClosingEventArgs e)
{
return;
}
private void ComboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}