예제 #1
0
        private void btnSave_ClickEvent(object sender, EventArgs e)
        {
            try
            {
                if (ValidateFomControls.CheckTextboxes(this, errorProvider1))
                {
                    _unitOfWork = new UnitOfWork(new Model1());
                    var ss = _unitOfWork.School_SubjectsRepository.FindById(_id).Result;

                    ss.subjects = txtSubject.Text;
                    _unitOfWork.Save();
                    dGridAllClass.DataSource = _unitOfWork.School_SubjectsRepository.FindAll().ToList();

                    _unitOfWork.Dispose();

                    btnSave.Enabled    = false;
                    txtSubject.Text    = string.Empty;
                    txtSubject.Enabled = false;
                    MessageBox.Show("Subject Updated");
                }
            }
            catch (Exception ex)
            {
                Utils.LogException(ex);
                MessageBox.Show("Error occured. Please contact support.");
            }
        }
예제 #2
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (ValidateFomControls.CheckTextboxes(this, errorProvider1) &&
                ValidateFomControls.CheckPassword(_txtPassword.Text, _txtConfirmPassword.Text))
            {
                var principal = CreatePrincipal();

                if (principal != null)
                {
                    try
                    {
                        _unitOfWork = new UnitOfWork(new Model1());
                        _unitOfWork.PrincipalRepository.Add(principal);
                        await _unitOfWork.Save();

                        _unitOfWork.Dispose();
                        MessageBox.Show("Admin added");
                    }
                    catch (Exception ex)
                    {
                        Utils.LogException(ex);

                        MessageBox.Show("An error occured. Please contact Admin");
                    }
                }
                else
                {
                    MessageBox.Show("Error occured. Contact support");
                }
            }
        }
예제 #3
0
        private async void btnSave_ClickEventAsync(object sender, EventArgs e)
        {
            if (ValidateFomControls.CheckTextboxes(this, errorProvider1) &&
                ValidateFomControls.CheckPassword(_txtPassword.Text, _txtConfirmPassword.Text) &&
                ValidateFomControls.CheckComboBoxes(this, errorProvider1))
            {
                try
                {
                    var teacher = CreateTeacher();

                    if (teacher != null)
                    {
                        _unitOfWork = new UnitOfWork(new Model1());
                        _unitOfWork.TeacherRepository.Add(teacher);
                        await _unitOfWork.Save();

                        _unitOfWork.Dispose();
                        MessageBox.Show("Teacher added");
                    }
                    else
                    {
                        ArgumentNullException ex = new ArgumentNullException("Teacher object", "Teacher object is null");
                        Utils.LogException(ex);
                        MessageBox.Show("Error occured. Contact support");
                    }
                }
                catch (Exception ex)
                {
                    Utils.LogException(ex);
                    MessageBox.Show("An error occured. Please contact support");
                }
            }
        }
예제 #4
0
 private void btnSave_ClickEvent(object sender, EventArgs e)
 {
     if (ValidateFomControls.CheckTextboxes(this, errorProvider1))
     {
         try
         {
             var _unitOfWork = new UnitOfWork(new Model1());
             var sch_subj    = CreateSchoolSubject();
             if (!_unitOfWork.School_SubjectsRepository.CheckIfItExists(_txtSubject.Text))
             {
                 _unitOfWork.School_SubjectsRepository.Add(sch_subj);
                 _unitOfWork.Save();
                 _unitOfWork.Dispose();
                 MessageBox.Show("New Subject Added");
             }
             else
             {
                 MessageBox.Show("Already Added");
             }
         }
         catch (Exception ex)
         {
             Utils.LogException(ex);
             MessageBox.Show("An error occured. Please contact support");
         }
     }
 }
예제 #5
0
        private void btnSave_ClickEvent(object sender, EventArgs e)
        {
            try
            {
                if (ValidateFomControls.CheckTextboxes(this, errorProvider1))
                {
                    if (string.IsNullOrWhiteSpace(_logoLocation) || string.IsNullOrWhiteSpace(_stampLocation))
                    {
                        MessageBox.Show("Please Enter the School Logo and Stamp.");
                        return;
                    }
                    var admin = new administrative()
                    {
                        school_logo  = _logoLocation,
                        school_motto = _stampLocation,
                        school_name  = _txtName.Text,
                        school_stamp = _txtAddress.Text,
                        upload_date  = DateTime.Now.Date.ToString("d"),
                        upload_time  = DateTime.Now,
                    };
                    using (var db = new Model1())
                    {
                        if (db.administratives.Count() < 1)
                        {
                            db.administratives.Add(admin);
                        }
                        else
                        {
                            var cur = db.administratives.First();
                            cur.school_logo  = _logoLocation;
                            cur.school_motto = _stampLocation;
                            cur.school_name  = _txtName.Text;
                            cur.school_stamp = _txtAddress.Text;
                            cur.upload_date  = DateTime.Now.Date.ToString("d");
                            cur.upload_time  = DateTime.Now;
                        }

                        db.SaveChanges();
                    }
                    MessageBox.Show("Scho0l Info was saved successfully.");
                }
            }
            catch (Exception ex)
            {
                Utils.LogException(ex);
                MessageBox.Show("An error occured.\n");
            }
        }
예제 #6
0
        private async void btnSave_ClickEvent(object sender, EventArgs e)
        {
            if (ValidateFomControls.CheckTextboxes(this, errorProvider1))
            {
                if (RegexCheckTextbox(_txtSession.Text) && CheckIfSessionIsValid(_txtSession.Text))
                {
                    try
                    {
                        _unitOfWork = new UnitOfWork(new Model1());

                        if (_unitOfWork.SessionRepository.CheckIfItExists(_txtSession.Text))
                        {
                            MessageBox.Show("This session already exists.");
                            return;
                        }

                        var Session = new session()
                        {
                            sessions   = _txtSession.Text,
                            date_added = DateTime.Today.ToString("d"),
                            time_added = DateTime.Now,
                        };

                        _unitOfWork.SessionRepository.Add(Session);
                        await _unitOfWork.Save();

                        _unitOfWork.Dispose();
                        MessageBox.Show($"Session {_txtSession.Text} was added successfully.");
                    }
                    catch (Exception ex)
                    {
                        Utils.LogException(ex);
                        MessageBox.Show("Error occured. Contact support");
                    }
                }
                else
                {
                    MessageBox.Show("Please enter the session in the approved format");
                }
            }
        }
예제 #7
0
        private void btnSave_ClickEvent(object sender, EventArgs e)
        {
            if (ValidateFomControls.CheckTextboxes(this, errorProvider1))
            {
                try
                {
                    var _unitOfWork = new UnitOfWork(new Model1());
                    if (_unitOfWork.dClassRepository.CheckIfItExists(_txtClassName.Text.Trim()))
                    {
                        MessageBox.Show("This class already exists.");
                        return;
                    }

                    var cl = new _class()
                    {
                        classes    = _txtClassName.Text.Trim(),
                        date_added = DateTime.Today.ToString("d"),
                        time_added = DateTime.Now
                    };

                    _unitOfWork.dClassRepository.Add(cl);
                    _unitOfWork.Save();
                    _unitOfWork.Dispose();
                    MessageBox.Show("Class Added Successfully");

                    using (var db = new Model1())
                    {
                        classes = db.classes.ToList();
                        dGridAllClass.DataSource = classes;
                    }
                }
                catch (Exception ex)
                {
                    Utils.LogException(ex);
                    MessageBox.Show("Error occured. Contact support");
                }
            }
        }
예제 #8
0
        private void btnSave_ClickEvent(object sender, EventArgs e)
        {
            if (ValidateFomControls.CheckTextboxes(this, errorProvider1) && ValidateFomControls.CheckComboBoxes(this, errorProvider1))
            {
                if (btnFind.Enabled)
                {
                    MessageBox.Show("Click Find to make sure the reg number exists first.");
                    return;
                }
                var rtn = MessageBox.Show($"Are you sure you want to move this student from {_txtCurClass.Text} to {cboxToClass.Text}?", "", MessageBoxButtons.YesNo);
                if (rtn == DialogResult.Yes)
                {
                    try
                    {
                        using (var db = new Model1())
                        {
                            var stu = db.students.FirstOrDefault(x => x.reg_number == _txtRegNumber.Text);

                            if (stu == null)
                            {
                                MessageBox.Show("No student was found with this reg number.");
                            }
                            else
                            {
                                stu._class = cboxToClass.Text;
                                db.SaveChanges();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Utils.LogException(ex);
                        MessageBox.Show("Error occured. Please contact support.");
                    }
                }
            }
        }
예제 #9
0
        private void btnSave_ClickEvent(object sender, EventArgs e)
        {
            if (ValidateFomControls.CheckComboBoxes(this, errorProvider1) && ValidateFomControls.CheckTextboxes(this, errorProvider1))
            {
                if (cboxType.Text == "Student")
                {
                    try
                    {
                        using (var db = new Model1())
                        {
                            var stud = db.students.FirstOrDefault(x => x.reg_number == _txtUsername.Text);
                            if (stud != null)
                            {
                                stud.gen_password = _txtPassword.Text;
                                db.SaveChanges();
                                MessageBox.Show("Password changed");
                            }
                            else
                            {
                                MessageBox.Show("No user found");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Utils.LogException(ex);
                        MessageBox.Show("An error occured. Please contact admin");
                    }
                }
                else if (cboxType.Text == "Teacher")
                {
                    try
                    {
                        using (var db = new Model1())
                        {
                            var tech = db.teachers.FirstOrDefault(x => x.username == _txtUsername.Text);

                            if (tech != null)
                            {
                                tech.password = _txtPassword.Text;
                                db.SaveChanges();
                                MessageBox.Show("Password changed");
                            }
                            else
                            {
                                MessageBox.Show("No user found");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Utils.LogException(ex);
                        MessageBox.Show("An error occured. Please contact admin");
                    }
                }
                else if (cboxType.Text == "Principal")
                {
                    try
                    {
                        using (var db = new Model1())
                        {
                            var prp = db.principals.FirstOrDefault(x => x.username == _txtUsername.Text);
                            if (prp != null)
                            {
                                prp.password = _txtPassword.Text;
                                db.SaveChanges();
                                MessageBox.Show("Password changed");
                            }
                            else
                            {
                                MessageBox.Show("No user found");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Utils.LogException(ex);
                        MessageBox.Show("An error occured. Please contact admin");
                    }
                }
                else if (cboxType.Text == "Admin")
                {
                    try
                    {
                        using (var db = new Model1())
                        {
                            var ad = db.users.FirstOrDefault(x => x.email == _txtUsername.Text);
                            if (ad != null)
                            {
                                ad.password = _txtPassword.Text;
                                db.SaveChanges();
                                MessageBox.Show("Password changed");
                            }
                            else
                            {
                                MessageBox.Show("User not found");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Utils.LogException(ex);
                        MessageBox.Show("An error occured. Please contact admin");
                    }
                }
            }
        }