private void btnFinalizeAttendance_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtDesc.Text.Trim()))
                {
                    txtDesc.Text = @"NA";
                }

                var dialogResult =
                    MessageBox.Show(
                        $@"Are you sure you want to Finalize this Session for {cmbCourse.Text} {
                                cmbAttendanceReason.Text
                            }. This is Irreversable!",
                        @"Waiting for Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dialogResult != DialogResult.Yes)
                {
                    return;
                }

                using (var localEntities = new LocalEntities())
                {
                    var attendanceSession = new School_AttendanceSession()
                    {
                        IsDeleted             = false,
                        AcademicPeriodId      = 0,
                        AttendanceDescription = txtDesc.Text,
                        AttendanceFunctionId  = (int)cmbAttendanceReason.SelectedValue,
                        AttendanceSessionGuid = Guid.NewGuid().ToString().ToUpper(),
                        CourseId     = (int)cmbCourse.SelectedValue,
                        DateRecorded = DateTime.Now,
                        IsUploaded   = false,
                        UserRecorded = DatabaseManager.CurrentAuthModel.AccessCredential.Id
                    };

                    localEntities.School_AttendanceSession.Add(attendanceSession);
                    localEntities.SaveChanges();

                    foreach (var attendance in _schoolAttendances)
                    {
                        attendance.AttendanceSessionId = attendanceSession.Id;
                    }

                    localEntities.School_Attendance.AddRange(_schoolAttendances);
                    localEntities.SaveChanges();
                }

                MessageBox.Show(@"Attendance Taken Successfully");
                this.CloseProcess();
            }
            catch (Exception exception)
            {
                ErrorHandler.TreatError(exception);
            }
        }
Esempio n. 2
0
        private void WriteExcel(DataGridViewRow gvRow, string location)
        {
            _workingState = true;

            try
            {
                var attendanceSessionId = Convert.ToInt32(gvRow.Cells[0].Value);
                var name = $"Attendance for {gvRow.Cells[4].Value} in {gvRow.Cells[3].Value}";

                using (var sw = new StreamWriter($"{location}/{name}.csv"))
                {
                    var writer = new CsvWriter(sw);

                    writer.WriteField(name);
                    writer.NextRecord();

                    writer.WriteField(@"Student Matric Number");
                    writer.WriteField(@"Record Period");
                    writer.NextRecord();

                    using (var localEntities = new LocalEntities())
                    {
                        var attendanceData = localEntities.School_Attendance
                                             .Where(x => !x.IsDeleted && x.AttendanceSessionId == attendanceSessionId).Select(x => new
                        {
                            x.StudentMatricNumber,
                            RecordPeriod = x.DateRecorded.ToString()
                        }).ToList();

                        writer.WriteRecords(attendanceData);

                        writer.WriteField(@"");
                        writer.NextRecord();
                        writer.WriteField(@"");
                        writer.NextRecord();

                        writer.WriteField(@"Total Attendance " + attendanceData.Count);
                    }
                }
            }
            catch (Exception e)
            {
                ErrorHandler.TreatError(e);
            }

            _workingState = false;
        }
Esempio n. 3
0
        private void btnUpdateSettingsConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                new Thread(() =>
                {
                    _workingState = true;

                    var settings = RemoteRequest.Get($"{txtUrl.Text.Trim()}apisettings/PullSettings");
                    if (settings.Result.Status)
                    {
                        var settingData   = Newtonsoft.Json.JsonConvert.DeserializeObject <List <System_Setting> >(settings.Result.Data.ToString());
                        var localEntities = new LocalEntities();

                        if (!settingData.Any())
                        {
                            MessageBox.Show(@"No Settings were found on the server");
                            _workingState = false;
                            return;
                        }

                        DatabaseManager.ExecuteScripts("truncate table dbo.SystemSetting");

                        localEntities.System_Setting.AddRange(settingData.Select(sd => new System_Setting()
                        {
                            IsDeleted    = false,
                            SettingDate  = DateTime.Now,
                            SettingKey   = sd.SettingKey,
                            SettingValue = sd.SettingValue
                        }));
                        localEntities.SaveChanges();
                        DatabaseManager.UpdateSpec = new UpdateSpec()
                        {
                            DatabaseFiles  = DatabaseManager.UpdateSpec.DatabaseFiles,
                            DatabaseSchema = DatabaseManager.UpdateSpec.DatabaseSchema,
                            RemoteUrl      = settingData.FirstOrDefault(x => x.SettingKey == (int)SettingKey.RemoteApi)
                                             ?.SettingValue ?? ""
                        };
                    }
                    else
                    {
                        MessageBox.Show(@"The server cannot be reached at the moment. Please try again later!");
                    }


                    settings = RemoteRequest.Get($"{txtUrl.Text.Trim()}ApiUserManagement/Pullusers");

                    if (settings.Result.Status)
                    {
                        DatabaseManager.LocalAuthData =
                            Newtonsoft.Json.JsonConvert.DeserializeObject <List <AuthModel> >(
                                Newtonsoft.Json.JsonConvert.SerializeObject(settings.Result.Data));

                        var x = DatabaseManager.LocalAuthData;
                    }
                    else
                    {
                        MessageBox.Show(@"The server cannot be reached at the moment. Please try again later!");
                    }
                    _workingState = false;
                }).Start();
            }
            catch (Exception exception)
            {
                ErrorHandler.TreatError(exception);
            }
        }
        void OnTagRead(NfcTag tag)
        {
            try
            {
                string msg;
                _tag         = tag;
                _studentData = null;

                if (_tag == null)
                {
                    msg = "Internal error, The Tag is Invalid!";
                    WarnNotify("Warning|" + msg);
                    return;
                }

                if ((tag.Content == null) || (tag.Content.Count == 0))
                {
                    if (!tag.IsLocked())
                    {
                        msg = "The Device has no valid content yet. You may proceed with Tag Writting.";
                        WarnNotify("Warning|" + msg);
                    }
                    else
                    {
                        msg = "The Tag has no valid content, but is not writable";
                        WarnNotify("Warning|" + msg);
                    }
                }
                else
                {
                    var ndef = tag.Content.FirstOrDefault();
                    switch (ndef)
                    {
                    case null:
                        msg = "This Tag is Empty.";
                        WarnNotify("Warning|" + msg);
                        return;

                    case RtdSmartPoster smart:
                        using (var localEntities = new LocalEntities())
                        {
                            var matricNumber = smart.Title.FirstOrDefault()?.Value ?? "";
                            _studentData =
                                localEntities.Student_ProfileData.FirstOrDefault(x =>
                                                                                 x.MatricNumber == matricNumber && x.TagId == _tagUID);

                            msg = _studentData == null
                                    ? "No Student Record, Access Denied."
                                    : $"{_studentData.FirstName} {_studentData.LastName}, Access Granted";

                            var speak = new SpeechSynthesizer();
                            speak.SpeakAsync(msg);
                        }

                        SuccessNotify("Awesome|" + msg);
                        break;

                    default:
                        msg = "Data found but its not an EdBoxPremium Data.";
                        WarnNotify("Warning|" + msg);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.TreatError(ex);
            }
        }
        private void btnAttach_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtStudentMatric.Text.Trim() != _studentData.StudentProfileData.MatricNumber)
                {
                    MessageBox.Show(
                        @"Please request for the Student you wish to Tag. Some modifications have been made to the information retrieved.");
                    return;
                }

                if (_tag == null)
                {
                    MessageBox.Show(
                        @"Lets start over. Close this message and Place a blank Tag");
                    return;
                }

                if (!CheckTagValidity())
                {
                    var dialogResult =
                        MessageBox.Show(
                            @"The Current Tag has some data on it? This operation will totally overwrite it. Should I proceed?",
                            @"Waiting for Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (dialogResult != DialogResult.Yes)
                    {
                        return;
                    }
                }

                if (!RemoteTagClean())
                {
                    return;
                }

                var settings =
                    RemoteRequest.Get(
                        $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiStudentManagement/TagStudent?matricNumber={txtStudentMatric.Text.Trim()}&tagId={_tagUID}");

                if (!settings.Result.Status)
                {
                    MessageBox.Show(
                        @"Cannot Write Tag at the moment. Why? " + settings.Result.Message);
                    return;
                }

                var smartPoster = new RtdSmartPoster();
                smartPoster.Title.Add(new RtdText(_studentData.StudentProfileData.MatricNumber, "US"));
                Ndef ndefData = smartPoster;

                using (var localEntities = new LocalEntities())
                {
                    var recordInDb =
                        localEntities.Student_ProfileData.FirstOrDefault(x =>
                                                                         x.MatricNumber == txtStudentMatric.Text.Trim());

                    if (recordInDb != null)
                    {
                        recordInDb.TagId = _tagUID;
                        localEntities.Entry(recordInDb).State = EntityState.Modified;
                        localEntities.SaveChanges();
                    }
                }

                _tag.Content.Clear();
                _tag.Content.Add(ndefData);
                _cardthread = new Thread(() => { card_write_proc(_tag); });
                _cardthread.Start();
            }
            catch (Exception exception)
            {
                ErrorHandler.TreatError(exception);
            }
        }
Esempio n. 6
0
        private void PullStudents()
        {
            try
            {
                var listOfProfileData  = new List <List <Data.Student_ProfileData> >();
                var listOfAcademicData = new List <List <Student_RegistrationData> >();

                var done = 0;

                _consoleInfoData = "Starting Pull of Student Data";
                while (true)
                {
                    var settings =
                        RemoteRequest.Get(
                            $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiStudentManagement/PullStudentsCompleteData?done={done}");

                    if (settings.Result.Status)
                    {
                        var batch = Newtonsoft.Json.JsonConvert.DeserializeObject <List <StudentCompleteData> >(
                            Newtonsoft.Json.JsonConvert.SerializeObject(settings.Result.Data));

                        if (!batch.Any())
                        {
                            break;
                        }

                        listOfProfileData.Add(batch.Select(x => x.StudentProfileData).ToList());
                        listOfAcademicData.Add(batch
                                               .Select(x => x.StudentData.FirstOrDefault()?.StudentRegistrationData).ToList());

                        done            += batch.Count;
                        _consoleInfoData = $"Pulled Student Batch of {batch.Count}. Total Pulled is {done}";
                    }
                    else
                    {
                        _consoleInfoData = $"Issue with Synchronization of Student Data. Please contact the Adminsitrator";
                        return;
                    }
                }

                if (listOfProfileData.Any())
                {
                    _consoleInfoData = @"Discarding all Previous Records";
                    DatabaseManager.ExecuteScripts("truncate table dbo.Student_ProfileData");

                    using (var data = new LocalEntities())
                    {
                        _consoleInfoData = @" Persisting Student Profile Data";
                        foreach (var list in listOfProfileData)
                        {
                            _consoleInfoData = @"Processing ...";
                            data.Student_ProfileData.AddRange(list.Select(innerList => new Student_ProfileData()
                            {
                                MatricNumber   = innerList.MatricNumber,
                                TagId          = innerList.TagId,
                                IsDeleted      = false,
                                Phone          = innerList.Phone,
                                FirstName      = innerList.FirstName,
                                Email          = innerList.Email,
                                LastName       = innerList.LastName,
                                Sex            = innerList.Sex,
                                Picture        = innerList.Picture,
                                BloodGroup     = innerList.BloodGroup ?? "",
                                PictureEncoded =
                                    string.IsNullOrEmpty(innerList.Picture)
                                        ? null
                                        : Convert.FromBase64String(innerList.Picture),
                                StudentProfileData = Newtonsoft.Json.JsonConvert.SerializeObject(innerList),
                                RemoteId           = innerList.Id
                            }));
                            data.SaveChanges();
                        }
                        _consoleInfoData = @"Student Profile Data Persistence Successful";

                        _consoleInfoData = @"Persisting Student Academic Data";
                        foreach (var acadBatch in listOfAcademicData)
                        {
                            _consoleInfoData = @"Processing ...";
                            foreach (var acad in acadBatch)
                            {
                                var profile =
                                    data.Student_ProfileData.FirstOrDefault(x => x.RemoteId == acad.StudentId);

                                if (profile == null)
                                {
                                    continue;
                                }

                                var school =
                                    DatabaseManager.AcademicSetUpData.AcademicSetUpDatum.FirstOrDefault(x =>
                                                                                                        x.SchoolSubSchool.Id == acad.SubSchoolId);

                                if (school == null)
                                {
                                    continue;
                                }

                                profile.Program    = school.SchoolSubSchool.SubSchoolName;
                                profile.Department = school.SchoolSubSchoolDepartment
                                                     .FirstOrDefault(x => x.Id == acad.SubSchoolDepartmentId)?.SubSchoolDepartmentName;

                                data.Entry(profile).State = EntityState.Modified;
                            }
                            data.SaveChanges();
                        }
                        _consoleInfoData = @"Student Academic Data Persistence Successful";
                    }
                    _consoleInfoData = @"Completed Pull of Student Data";
                }
                else
                {
                    _consoleInfoData = @"No Records found at this time.";
                }
            }
            catch (Exception e)
            {
                ErrorHandler.TreatError(e);
            }
        }