Beispiel #1
0
 internal void OnSaveNoteButtonClick()
 {
     if (view.TextBoxComment != string.Empty)
     {
         var note = new Model.Note()
         {
             note1 = view.TextBoxComment, note_date = DateTime.Now, note_seen = false, student_id = view.SelectedStudentID, subject_id = view.SelectedSubjectID
         };
         data.Notes.Add(note);
         try
         {
             data.SaveChanges();
         }
         catch (Exception)
         {
             view.Message("В момента изпитваме технически затруднения. Възможно е вашите промени да не са запазени. Моля, опитайте отново по-късно. Съжаляваме за причененото неудобство.", "Грешка", Views.MessageIcon.Error);
             return;
         }
         view.HideAll();
         view.Message("Забележката е добавена.", "Успешен запис", Views.MessageIcon.Information);
     }
     else
     {
         view.Message("Не можете да добавите празна забележка.", "Грешка", Views.MessageIcon.Error);
     }
 }
Beispiel #2
0
        public void OnSaveNameChangesButtonClick()
        {
            if (view.FirstNameTextBoxText == string.Empty || view.LastNameTextBoxText == string.Empty)
            {
                view.Message("Моля, въведето ново лично и фамилно име.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            if (!Regex.IsMatch(view.FirstNameTextBoxText, @"^[А-я]+$") || !Regex.IsMatch(view.LastNameTextBoxText, @"^[А-я]+$"))
            {
                view.Message("Моля, използвайте само букви от българската азбука за вашето собствено име и фамилия.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            user.FirstName = view.FirstNameTextBoxText;
            user.LastName  = view.LastNameTextBoxText;

            try
            {
                data.SaveChanges();
                view.Message("Промените бяха запазени успешно.", "Успех", Views.MessageIcon.Information);
            }
            catch (Exception)
            {
                view.Message("В момента изпитваме технически затруднения. Възможно е вашите промени да не са запазени. Моля, опитайте отново по-късно. Съжаляваме за причененото неудобство.", "Грешка", Views.MessageIcon.Error);
            }

            view.DisplayMainScreen();
        }
Beispiel #3
0
        public void SaveChanges(bool isSavingOnDataViewChange = false)
        {
            if (currentNotes == null && currentGrades == null)
            {
                return;
            }

            // Propagate the changes to the entity objects tracked by DbContext instance and commit them to the database
            if (view.SelectedGradesView ^ isSavingOnDataViewChange)
            {
                var gradesWithChangedSeenStatus = currentGrades.Where(x => x.grade_seen != (dataForGridView as IEnumerable <Views.GradeViewData>).Where(y => y.ID == x.grade_id).Single().Seen).ToList();
                foreach (var grade in gradesWithChangedSeenStatus)
                {
                    grade.grade_seen = !grade.grade_seen;
                }
            }
            else
            {
                var notesWithChangedSeenStatus = currentNotes.Where(x => x.note_seen != (dataForGridView as IEnumerable <Views.NoteViewData>).Where(y => y.ID == x.note_Id).Single().Seen).ToList();
                foreach (var note in notesWithChangedSeenStatus)
                {
                    note.note_seen = !note.note_seen;
                }
            }

            try
            {
                data.SaveChanges();
                //throw new Exception();
            }
            catch (Exception)
            {
                if (!isSavingOnDataViewChange)
                {
                    view.Message("В момента изпитваме технически затруднения. Възможно е вашите промени да не са запазени. Моля, опитайте отново по-късно. Съжаляваме за причененото неудобство.", "Грешка", Views.MessageIcon.Error);
                }
            }
        }
Beispiel #4
0
        public void OnSaveClick()
        {
            string typeOfProfile = view.typeOfProfile;
            var    regexString   = new Regex("^[А-я]+$");
            var    regexInt      = new Regex("^[0-9]+$");
            var    regexPassword = new Regex("^.{8,25}$");
            var    regexUserName = new Regex("^[A-Za-z0-9_]+$");
            Random random        = new Random();
            int    randomNum     = random.Next();

            switch (typeOfProfile)
            {
            case "Учител":
                if (view.UserNameTextBox != string.Empty && view.TextBoxSubject != string.Empty && view.FirstNTextBox != string.Empty &&
                    view.LastNTextBox != string.Empty && view.Password != string.Empty && regexString.IsMatch(view.FirstNTextBox) &&
                    regexString.IsMatch(view.LastNTextBox) && regexString.IsMatch(view.TextBoxSubject) && regexUserName.IsMatch(view.UserNameTextBox))
                {
                    var existingTeacher = data.Teachers.Where(x => x.username == view.UserNameTextBox).SingleOrDefault();

                    if (existingTeacher != null)
                    {
                        view.Message("Това потребителско име вече е заето. Моля, изберете друго.", "Внимание", Views.MessageIcon.Warning);
                        return;
                    }
                    if (!regexPassword.IsMatch(view.Password))
                    {
                        view.Message("Паролата трябва да е с дължина между 8 и 25 символа.", "Внимание", Views.MessageIcon.Warning);
                        return;
                    }

                    Utilities.IPasswordHash passHasher = new Utilities.PasswordHash();
                    var passHash = passHasher.Generate(view.PasswordTextBox.ToString());
                    var teacher  = new Model.Teacher()
                    {
                        username = view.UserNameTextBox, teacher_firstN = view.FirstNTextBox, teacher_lastN = view.LastNTextBox, password_hash = passHash
                    };
                    data.Teachers.Add(teacher);
                    var teacherid = teacher.teacher_id;
                    var subject   = new Model.Subject()
                    {
                        subject_name = view.TextBoxSubject, teacher_id = teacherid
                    };
                    data.Subjects.Add(subject);
                }
                else
                {
                    view.Message("Моля попълнете всички полета коректно.", "Грешка", Views.MessageIcon.Error);
                    return;
                }
                break;

            case "Ученик":

                if (view.ComboBoxGrade != null && view.FirstNTextBox != string.Empty && view.LastNTextBox != string.Empty &&
                    view.PINTextBox != string.Empty && regexInt.IsMatch(view.PINTextBox) &&
                    regexString.IsMatch(view.FirstNTextBox) && regexString.IsMatch(view.LastNTextBox))
                {
                    var student = new Model.Student()
                    {
                        student_firstN = view.FirstNTextBox, student_lastN = view.LastNTextBox, grade = view.ComboBoxGrade, student_PIN = view.PINTextBox, code = randomNum.ToString()
                    };
                    data.Students.Add(student);
                }
                else
                {
                    view.Message("Моля попълнете всички полета коректно.", "Грешка", Views.MessageIcon.Error);
                    return;
                }

                break;
            }

            try
            {
                data.SaveChanges();
                if (typeOfProfile == "Учител")
                {
                    view.Message("Успешно направен профил на учител!", "Успех", Views.MessageIcon.Information);
                }
                else
                {
                    view.Message(String.Format("Успешно направен профил на ученик с код: {0}", randomNum.ToString()), "Успех", Views.MessageIcon.Information);
                    string path        = "StudentsProfiles.txt";
                    string studentInfo = String.Concat(view.PINTextBox + " ", view.FirstNTextBox + " ", view.LastNTextBox + " ", randomNum.ToString(), "\n");
                    File.AppendAllText(path, studentInfo);
                }
                view.ClearText();
            }
            catch (Exception)
            {
                view.Message("В момента изпитваме технически затруднения. Възможно е вашите промени да не са запазени. Моля, опитайте отново по-късно. Съжаляваме за причененото неудобство.", "Грешка", Views.MessageIcon.Error);
                return;
            }
        }
Beispiel #5
0
        public void OnCreateButtonClick()
        {
            if (view.Username == string.Empty)
            {
                view.Message("Моля, въведете потребителско име.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            if (view.Pass == string.Empty)
            {
                view.Message("Моля, въведете парола.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            if (view.FirstName == string.Empty || view.Surname == string.Empty)
            {
                view.Message("Моля, въведете вашето лично име и фамилия.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            if (!Regex.IsMatch(view.FirstName, @"^[А-я]+$") || !Regex.IsMatch(view.Surname, @"^[А-я]+$"))
            {
                view.Message("Моля, използвайте само букви от българската азбука за вашето собствено име и фамилия.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            if (!Regex.IsMatch(view.Username, @"^[A-Za-z0-9_]+$"))
            {
                view.Message("Моля, въведете валидно потребтилеско име (разрешени са буквите от английската азбука, цифрите 0-9 и долна черта).", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            var existingParent  = data.Parents.Where(x => x.username == view.Username).SingleOrDefault();
            var existingTeacher = data.Teachers.Where(x => x.username == view.Username).SingleOrDefault();
            var existingAdmin   = data.Admins.Where(x => x.admin_username == view.Username).SingleOrDefault();

            if (existingParent != null || existingTeacher != null || existingAdmin != null)
            {
                view.Message("Това потребителско име вече е заето. Моля, изберете друго.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            if (!Regex.IsMatch(view.Pass, @"^.{8,25}$"))
            {
                view.Message("Моля, въведете парола с дължина между 8 и 25 символа.", "Внимание", Views.MessageIcon.Warning);
                return;
            }

            Utilities.IPasswordHash passHasher = new Utilities.PasswordHash();
            var passHash = passHasher.Generate(view.Pass);

            var newParent = new Model.Parent()
            {
                parent_firstN = view.FirstName, parent_lastN = view.Surname, username = view.Username, password_hash = passHash
            };

            data.Parents.Add(newParent);

            try
            {
                data.SaveChanges();
            }
            catch (Exception)
            {
                view.Message("В момента изпитваме технически затруднения. Моля, опитайте отново по-късно. Съжаляваме за причененото неудобство.", "Грешка", Views.MessageIcon.Error);
                return;
            }

            view.Message("Вашият профил беше създаден успешно. Можете да го използвате.", "Успех", Views.MessageIcon.Information);
            view.Close();
            loginPresenter.ShowLoginView();
        }