public Mark_Attendance_Form()
        {
            InitializeComponent();
            loadcourses  = new Linked_List <Course>();
            student_list = new Linked_List <Student>();

            string serializationFile = "course_file.bin";

            using (Stream stream = File.Open(serializationFile, FileMode.Open))
            {
                var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                loadcourses = (Linked_List <Course>)bformatter.Deserialize(stream);
            }
            for (ListNode <Course> temp = loadcourses.getHead(); temp != null; temp = temp.next)
            {
                courseBox.Items.Add(temp.val.get_String());
            }

            courseBox.Text = "Subject";
            idLabel.Text   = "";


            string studentfile = "student_file.bin";

            using (Stream stream = File.Open(studentfile, FileMode.Open))
            {
                var bformatter = new BinaryFormatter();

                student_list = (Linked_List <Student>)bformatter.Deserialize(stream);
            }

            face = new HaarCascade("haarcascade_frontalface_default.xml");
            //eye = new HaarCascade("haarcascade_eye.xml");
            try
            {
                //Load of previus trainned faces and labels for each image
                string   Labelsinfo = File.ReadAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt");
                string[] Labels     = Labelsinfo.Split('%');
                NumLabels = Convert.ToInt16(Labels[0]);
                ContTrain = NumLabels;
                string LoadFaces;

                for (int tf = 1; tf < NumLabels + 1; tf++)
                {
                    LoadFaces = "face" + tf + ".bmp";
                    trainingImages.Add(new Image <Gray, byte>(Application.StartupPath + "/TrainedFaces/" + LoadFaces));
                    labels.Add(Labels[tf]);
                }
            }
            catch
            {
                MessageBox.Show("Nothing in binary database, please add at least a face(Simply train the prototype with the Add Face Button).", "Triained faces load", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            for (ListNode <Student> temp = student_list.getHead(); temp != null; temp = temp.next)
            {
                if (temp.val.get_rollno() == delStudentBox.Text)
                {
                    std = temp;
                }
            }
            student_list.delete(std);
            string studentfile = "student_file.bin";

            using (Stream stream = File.Open(studentfile, FileMode.Create))
            {
                var bformatter = new BinaryFormatter();

                bformatter.Serialize(stream, student_list);
            }
            button1.Hide();
            delStudentBox.Hide();
            MessageBox.Show("Deleted Successfully");
        }
        private void button2_Click(object sender, EventArgs e)
        {
            for (ListNode <Course> temp = courses.getHead(); temp != null; temp = temp.next)
            {
                if (temp.val.get_course_code() == delCourseBox.Text)
                {
                    crs = temp;
                }
            }
            MessageBox.Show(crs.val.get_course_code());
            courses.delete(crs);
            string serializationFile = "course_file.bin";

            using (Stream stream = File.Open(serializationFile, FileMode.Create))
            {
                var bformatter = new BinaryFormatter();

                bformatter.Serialize(stream, courses);
            }
            button2.Hide();
            delCourseBox.Hide();
            MessageBox.Show("Deleted Successfully");
        }
        private void attendanceBtn_Click(object sender, EventArgs e)
        {
            if (courseBox.Text == "Subject")
            {
                MessageBox.Show("All entries must be filled");
            }
            else if (cameraBtn.Text == "Camera: Off")
            {
                MessageBox.Show("Can not mark attendance. Please open camera");
            }
            else if (String.IsNullOrEmpty(name))
            {
                MessageBox.Show("Can not mark attendance. Person not recognized");
            }
            else
            {
                BinarySearchTree bst = new BinarySearchTree();
                for (ListNode <Student> temp = student_list.getHead(); temp != null; temp = temp.next)
                {
                    bst.Insert(temp.val);
                }
                BinNode bstnode = bst.FindByValue(name);
                std = bstnode.data;
                for (ListNode <Course> temp = std.studentcourses.getHead(); temp != null; temp = temp.next)
                {
                    if (temp.val.get_String().Equals(courseBox.Text))
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    MessageBox.Show("Can not mark.student not registerted");
                    return;
                }
                string attendance_file = courseBox.Text + " " + DateTime.Now.ToString("d-M-yyyy") + ".xls";
                if (File.Exists(attendance_file))
                {
                    // open xls file
                    Workbook  book  = Workbook.Load(attendance_file);
                    Worksheet sheet = book.Worksheets[0];

                    // traverse rows by Index
                    for (int rowIndex = sheet.Cells.FirstRowIndex; rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
                    {
                        Row row = sheet.Cells.GetRow(rowIndex);
                        if (row.GetCell(0).ToString().Equals(name))
                        {
                            row.SetCell(2, new Cell("Present"));
                        }
                        for (int colIndex = row.FirstColIndex; colIndex <= row.LastColIndex; colIndex++)
                        {
                            Cell cell = row.GetCell(colIndex);
                        }
                    }

                    book.Save(attendance_file);
                }
                else
                {
                    //create new xls file
                    Workbook  workbook  = new Workbook();
                    Worksheet worksheet = new Worksheet("First Sheet");
                    worksheet.Cells.ColumnWidth[0, 0] = 6000;
                    worksheet.Cells.ColumnWidth[0, 1] = 6000;
                    worksheet.Cells.ColumnWidth[0, 2] = 6000;
                    worksheet.Cells[0, 0]             = new Cell("Roll Number");
                    worksheet.Cells[0, 1]             = new Cell("Name");
                    worksheet.Cells[0, 2]             = new Cell("Attendance");
                    for (ListNode <Student> temp = student_list.getHead(); temp != null; temp = temp.next)
                    {
                        for (ListNode <Course> temp1 = temp.val.studentcourses.getHead(); temp1 != null; temp1 = temp1.next)
                        {
                            if (temp1.val.get_String().Equals(courseBox.Text))
                            {
                                if (name.Equals(temp.val.get_rollno()))
                                {
                                    int r = worksheet.Cells.LastRowIndex;
                                    worksheet.Cells[r + 1, 0] = new Cell(temp.val.get_rollno());
                                    worksheet.Cells[r + 1, 1] = new Cell(temp.val.get_name());
                                    worksheet.Cells[r + 1, 2] = new Cell("Present");
                                }
                                else
                                {
                                    int r = worksheet.Cells.LastRowIndex;
                                    worksheet.Cells[r + 1, 0] = new Cell(temp.val.get_rollno());
                                    worksheet.Cells[r + 1, 1] = new Cell(temp.val.get_name());
                                    worksheet.Cells[r + 1, 2] = new Cell("Absent");
                                }
                            }
                        }
                    }
                    workbook.Worksheets.Add(worksheet);
                    workbook.Save(attendance_file);
                }
                MessageBox.Show("Attendance Marked Successfully");
                this.Hide();
                this.Close();
                Form1 form1 = new Form1();
                form1.ShowDialog();
                // traverse cells
                //foreach (Pair, Cell > cell in sheet.Cells)
                //{
                //    dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
                //}
            }
        }
        private void trainBtn_Click(object sender, EventArgs e)
        {
            try
            {
                //Trained face counter
                ContTrain = ContTrain + 1;

                //Get a gray frame from capture device
                gray = grabber.QueryGrayFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

                //Face Detector
                MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
                    face,
                    1.2,
                    10,
                    Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                    new Size(20, 20));

                //Action for each element detected
                foreach (MCvAvgComp f in facesDetected[0])
                {
                    TrainedFace = currentFrame.Copy(f.rect).Convert <Gray, byte>();
                    break;
                }

                //resize face detected image for force to compare the same size with the
                //test image with cubic interpolation type method
                TrainedFace = result.Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                trainingImages.Add(TrainedFace);
                labels.Add(rollnoBox.Text);

                //Show face added in gray scale
                pictureBox2.Image = TrainedFace.ToBitmap();

                //Write the number of triained faces in a file text for further load
                File.WriteAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt", trainingImages.ToArray().Length.ToString() + "%");

                //Write the labels of triained faces in a file text for further load
                for (int i = 1; i < trainingImages.ToArray().Length + 1; i++)
                {
                    trainingImages.ToArray()[i - 1].Save(Application.StartupPath + "/TrainedFaces/face" + i + ".bmp");
                    File.AppendAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt", labels.ToArray()[i - 1] + "%");
                }

                Student student = new Student(nameBox.Text, rollnoBox.Text);

                foreach (var index in courseListBox.CheckedIndices)
                {
                    ListNode <Course> temp = loadcourses.getHead();
                    for (int i = 0; temp != null; i++, temp = temp.next)
                    {
                        if (i == (int)index)
                        {
                            break;
                        }
                    }
                    student.studentcourses.Add(temp.val);
                }
                student_list.Add(student);
                string studentfile = "student_file.bin";

                //serialize
                using (Stream stream = File.Open(studentfile, FileMode.Create))
                {
                    var bformatter = new BinaryFormatter();

                    bformatter.Serialize(stream, student_list);
                }


                MessageBox.Show(nameBox.ToString() + "Student registered", "Training OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exc)
            {
                MessageBox.Show("Failed To Register " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            this.Hide();
            Form1 form1 = new Form1();

            form1.ShowDialog();
        }
        public student_form()
        {
            InitializeComponent();
            loadcourses  = new Linked_List <Course>();
            student_list = new Linked_List <Student>();

            string serializationFile = "course_file.bin";

            using (Stream stream = File.Open(serializationFile, FileMode.Open))
            {
                var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                loadcourses = (Linked_List <Course>)bformatter.Deserialize(stream);
            }
            for (ListNode <Course> item_c = loadcourses.getHead(); item_c != null; item_c = item_c.next)
            {
                courseListBox.Items.Add(item_c.val.get_String());
            }

            string studentfile = "student_file.bin";

            using (Stream stream = File.Open(studentfile, FileMode.Open))
            {
                var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                student_list = (Linked_List <Student>)bformatter.Deserialize(stream);
            }
            //foreach(var item in student_list)
            //{
            //    for(int j=0;j<courseListBox.Items.Count;j++)
            //    {
            //        courseListBox.SetItemChecked(j, false);
            //    }
            //    nameBox.Text = item.get_name();
            //    rollnoBox.Text = item.get_rollno();
            //    foreach(var i in item.studentcourses)
            //    {
            //        for(int ind=0;ind<courseListBox.Items.Count;ind++)
            //        {
            //            if(courseListBox.Items[ind].ToString().Equals(i.get_String()))
            //            {
            //                courseListBox.SetItemChecked(ind, true);
            //            }
            //        }
            //    }
            //    MessageBox.Show("done");
            //}


            face = new HaarCascade("haarcascade_frontalface_default.xml");
            //eye = new HaarCascade("haarcascade_eye.xml");
            try
            {
                //Load of previus trainned faces and labels for each image
                string   Labelsinfo = File.ReadAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt");
                string[] Labels     = Labelsinfo.Split('%');
                NumLabels = Convert.ToInt16(Labels[0]);
                ContTrain = NumLabels;
                string LoadFaces;

                for (int tf = 1; tf < NumLabels + 1; tf++)
                {
                    LoadFaces = "face" + tf + ".bmp";
                    trainingImages.Add(new Image <Gray, byte>(Application.StartupPath + "/TrainedFaces/" + LoadFaces));
                    labels.Add(Labels[tf]);
                }
            }
            catch
            {
                MessageBox.Show("Nothing in binary database, please add at least a face(Simply train the prototype with the Add Face Button).", "Triained faces load", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }