Exemplo n.º 1
0
        private void PunishButton_Click(object sender, RoutedEventArgs e)
        {
            StudentDisplay currentStudent = GetCurrentStudent(sender);
            MainWindow     window         = GlobalFunction.GetMainWindow();

            window._addFrame.Navigate(new AddPunishment(currentStudent.ID));
        }
Exemplo n.º 2
0
        private void DetailsButton_Click(object sender, RoutedEventArgs e)
        {
            StudentDisplay currentStudent = GetCurrentStudent(sender);
            MainWindow     window         = GlobalFunction.GetMainWindow();

            window._mainFrame.Navigate(new StudentDetailsPage(currentStudent.ID));
        }
Exemplo n.º 3
0
        private void DownvotesButton_Click(object sender, RoutedEventArgs e)
        {
            StudentDisplay currentStudent = GetCurrentStudent(sender);
            MainWindow     window         = GlobalFunction.GetMainWindow();

            window._addFrame.Navigate(new AddVote(false, currentStudent));
            //StudentsShared.AddVotesToDb(currentStudent.ID, false, "Downvote rapide");
            //int currentDownvoteCount = int.Parse(currentStudent.DownvotesCount);
            //currentDownvoteCount++;
            //currentStudent.DownvotesCount = currentDownvoteCount.ToString();
        }
Exemplo n.º 4
0
        private void RetrieveLastHomeworkButton_Click(object sender, RoutedEventArgs e)
        {
            StudentDisplay currentStudent = (StudentDisplay)((FrameworkElement)sender).DataContext;

            using SQLiteCommand cmd = GlobalFunction.OpenDbConnection();
            cmd.CommandText         = "UPDATE homeworks SET retrieveDate = @retrieveDate WHERE homeworkId = @id";
            cmd.Parameters.AddWithValue("id", currentStudent.LastHomeWorkId);

            int currentTimestamp = (int)new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds();

            cmd.Parameters.AddWithValue("retrieveDate", currentTimestamp);
            cmd.Prepare();
            cmd.ExecuteNonQuery();

            currentStudent.LastHomeworkStatusColor = "Green";
            currentStudent.LastHomeworkStatusText  = GlobalVariable.specialCharacter["CheckMark"];
            currentStudent.HomeworkButtonEnabled   = false;
        }
Exemplo n.º 5
0
        private void ReadStudentsData(List <int> studentIdList)
        {
            foreach (int studentId in studentIdList)
            {
                using SQLiteCommand cmd = GlobalFunction.OpenDbConnection();
                //Handle classroom name
                List <int>    classroomIdList   = Database.Get.Classroom.AllIDFromStudentID(studentId);
                List <string> classroomNameList = new List <string>();
                foreach (int classroomId in classroomIdList)
                {
                    classroomNameList.Add(Database.Get.Classroom.NameFromID(classroomId));
                }

                string classroomName = String.Join(", ", classroomNameList.ToArray());

                string[] studentName = Database.Get.Student.NameFromID(studentId);

                //Handle homework
                List <HomeworkInfo> homeworkList = GetAllHomeworks(studentId);
                HomeworkInfo        lastHomework = GetLastHomework(homeworkList);

                bool   lastHomeworkButtonEnabled = false;
                string lastHomeworkStatus        = GlobalVariable.specialCharacter["CheckMark"];
                string lastHomeworkColor         = "Green";
                if (lastHomework.retrieveDate == 0 && lastHomework.creationDate != 0)
                {
                    lastHomeworkButtonEnabled = true;
                    lastHomeworkStatus        = GlobalVariable.specialCharacter["Cross"];
                    lastHomeworkColor         = "Red";
                }

                //Handle note
                List <NoteInfo> notesList = GetAllNotes(studentId);
                NoteInfo        lastNotes = GetLastNote(notesList);

                //Handle votes
                List <VotesInfo> upvotesList   = Database.Get.Vote.AllFromStudentId(studentId, true);
                List <VotesInfo> downvotesList = Database.Get.Vote.AllFromStudentId(studentId, false);

                string average = "";

                List <GradeInfo> gradesList = Database.Get.Grade.AllFromStudentId(studentId);
                if (gradesList.Count == 0)
                {
                    average = "20/20";
                }
                else
                {
                    float[] gradesArray = new float[gradesList.Count];
                    int[]   coeffArray  = new int[gradesList.Count];
                    for (int i = 0; i < gradesList.Count; i++)
                    {
                        gradesArray[i] = gradesList[i].Grade;
                        coeffArray[i]  = gradesList[i].Coeff;
                    }

                    int     coeffSum            = coeffArray.Sum();
                    float[] gradesCoeffMultiply = new float[gradesList.Count];

                    for (int i = 0; i < gradesList.Count; i++)
                    {
                        gradesCoeffMultiply[i] = gradesArray[i] * coeffArray[i];
                    }

                    float gradesCoefMultiplySum = gradesCoeffMultiply.Sum();
                    float averageFloat          = gradesCoefMultiplySum / coeffSum;
                    average = averageFloat.ToString() + "/20";
                }

                StudentDisplay studentDisplay = new StudentDisplay()
                {
                    ID                      = studentId,
                    Name                    = studentName[1] + " " + studentName[0],
                    ClassroomName           = classroomName,
                    HomeworkButtonEnabled   = lastHomeworkButtonEnabled,
                    LastHomeworkStatusText  = lastHomeworkStatus,
                    LastHomeworkStatusColor = lastHomeworkColor,
                    LastHomeWorkId          = lastHomework.homeworkId,
                    Note                    = lastNotes.content ?? "Aucune note",
                    Average                 = average,
                    UpvotesCount            = upvotesList.Count.ToString(),
                    DownvotesCount          = downvotesList.Count.ToString()
                };
                studentsCollection.Add(studentDisplay);
            }
        }