private void BTN_DialogCourseAdd_Click(object sender, EventArgs e)
        {
            bool   pass = true;
            string msg  = "";
            int    i    = 1;

            if (!ValidateInput.IsValid(TXT_DialogCourseCode))
            {
                pass = false;
                msg += i + ". Course Code must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogCourseName))
            {
                pass = false;
                msg += i + ". Course Name must not be blank\n";
                i++;
            }

            // Send tmpCourseFee to function and not TXT_DialogCourseFee.Text
            decimal tmpCourseFee;

            if (!ValidateInput.IsValid(TXT_DialogCourseFee, true, out tmpCourseFee))
            {
                pass = false;
                msg += i + ". Fee Must be a valid amount\n";
                i++;
            }
            if (!pass)
            {
                msg += "\nRequired fields must be valid.";
                MessageBox.Show(null, msg, "Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }
            Course course = new Course()
            {
                CourseCode = TXT_DialogCourseCode.Text,
                Name       = TXT_DialogCourseName.Text,
                Fee        = tmpCourseFee
            };

            // If validation successful
            if (editUpdate)
            {
                if (cmd.UpdateCourse(course))
                {
                    mainForm.GetView("Colleges");
                }
            }
            else
            {
                if (cmd.AddCourse(course))
                {
                    mainForm.GetView("Colleges");
                }
            }
        }
        public void TestDecimalValidationToFail()
        {
            //Arrange
            string testDecimal = "z12.38";
            //Act
            bool passed = ValidateInput.IsValid(testDecimal, out decimal number);

            //Assert
            Assert.IsFalse(passed);
            //Assert.AreEqual(12.38m, number);
        }
        public void TestDecimalValidationOutputOnFailure()
        {
            //Arrange
            string testDecimal = "z12.38";
            //Act
            bool passed = ValidateInput.IsValid(testDecimal, out decimal number);

            //Assert
            //Assert.IsTrue(passed);
            Assert.AreEqual(0, number);
        }
        public void TestDateTimeComparisonToFail()
        {
            //Arrange
            DateTime before = new DateTime(2001, 3, 4);
            DateTime after  = new DateTime(2001, 3, 5);
            //Act
            bool passed = ValidateInput.IsValid(after, before);

            //Assert
            Assert.IsFalse(passed);
            //Assert.AreEqual(12.38m, number);
        }
        public void TestDateTimeComparison()
        {
            //Arrange
            DateTime before = new DateTime(2001, 3, 4); // 4th March, 2001
            DateTime after  = new DateTime(2001, 3, 5); // 5th March, 2001
            //Act
            bool passed = ValidateInput.IsValid(before, after);

            //Assert
            Assert.IsTrue(passed);
            //Assert.AreEqual(12.38m, number);
        }
 private void DGV_DialogEnrol_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex > -1 &&
         DGV_DialogEnrol.Rows[e.RowIndex].Cells["Enrol"].ColumnIndex == e.ColumnIndex &&
         DGV_DialogEnrol.Rows[e.RowIndex].Cells["Enrol"].ReadOnly == false)
     {
         if (ValidateInput.IsValid(DGV_DialogEnrol.Rows[e.RowIndex].Cells["Fee"].Value.ToString(), out decimal result))
         {
             fee = result;
         }
         EnrolStudent(DGV_DialogEnrol.Rows[e.RowIndex].Cells["CourseCode"].Value.ToString());
     }
 }
        private void BTN_DialogUnitAdd_Click(object sender, EventArgs e)
        {
            bool   pass = true;
            string msg  = "";
            int    i    = 1;

            if (!ValidateInput.IsValid(TXT_DialogUnitCode))
            {
                pass = false;
                msg += i + ". Unit Code must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogUnitDesc))
            {
                pass = false;
                msg += i + ". Description must not be blank\n";
                i++;
            }
            if (!pass)
            {
                msg += "\nRequired fields must be valid.";
                MessageBox.Show(null, msg, "Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }
            Unit unit = new Unit()
            {
                UnitCode    = TXT_DialogUnitCode.Text,
                Description = TXT_DialogUnitDesc.Text
            };

            // If validation successful
            if (editUpdate)
            {
                if (cmd.UpdateUnit(unit))
                {
                    mainForm.GetView("Units");
                }
            }
            else
            {
                if (cmd.AddUnit(unit))
                {
                    mainForm.GetView("Units");
                }
            }
        }
        private void BTN_DialogSubjectAdd_Click(object sender, EventArgs e)
        {
            bool   pass = true;
            string msg  = "";
            int    i    = 1;

            if (!ValidateInput.IsValid(TXT_DialogSubjectName))
            {
                pass = false;
                msg += i + ". Subject Name must not be blank\n";
                i++;
            }
            if (!pass)
            {
                msg += "\nRequired fields must be valid.";
                MessageBox.Show(null, msg, "Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }
            // If validation successful
            IMainDAL cmd = new MainDAL();

            if (editUpdate)
            {
                Subject subject = new Subject()
                {
                    Id   = int.Parse(LBL_DialogSubjectId.Text),
                    Name = TXT_DialogSubjectName.Text
                };
                if (cmd.UpdateSubject(subject))
                {
                    mainForm.GetView("Subjects");
                }
            }
            else
            {
                Subject subject = new Subject()
                {
                    Name = TXT_DialogSubjectName.Text
                };
                if (cmd.AddSubject(subject))
                {
                    mainForm.GetView("Subjects");
                }
            }
        }
        private void CMB_DialogSemesterYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            int theYear = int.Parse(CMB_DialogSemesterYear.Text);

            DateTime DateMin = new DateTime(theYear, 1, 1);
            DateTime DateMax = new DateTime(theYear, 12, 31);

            if (ValidateInput.IsValid(new DateTime(theYear, 1, 1), DTP_DialogSemesterFirstTermStart))
            {
                DTP_DialogSemesterFirstTermStart.MinDate  = DateMin;
                DTP_DialogSemesterFirstTermStart.MaxDate  = DateMax;
                DTP_DialogSemesterFirstTermEnd.MinDate    = DateMin;
                DTP_DialogSemesterFirstTermEnd.MaxDate    = DateMax;
                DTP_DialogSemesterSecondTermStart.MinDate = DateMin;
                DTP_DialogSemesterSecondTermStart.MaxDate = DateMax;
                DTP_DialogSemesterSecondTermEnd.MinDate   = DateMin;
                DTP_DialogSemesterSecondTermEnd.MaxDate   = DateMax;
            }
            else
            {
                DTP_DialogSemesterFirstTermStart.MaxDate  = DateMax;
                DTP_DialogSemesterFirstTermStart.MinDate  = DateMin;
                DTP_DialogSemesterFirstTermEnd.MaxDate    = DateMax;
                DTP_DialogSemesterFirstTermEnd.MinDate    = DateMin;
                DTP_DialogSemesterSecondTermStart.MaxDate = DateMax;
                DTP_DialogSemesterSecondTermStart.MinDate = DateMin;
                DTP_DialogSemesterSecondTermEnd.MaxDate   = DateMax;
                DTP_DialogSemesterSecondTermEnd.MinDate   = DateMin;
            }
            DTP_DialogSemesterFirstTermStart.Value  = DateMin;
            DTP_DialogSemesterFirstTermEnd.Value    = DateMin;
            DTP_DialogSemesterSecondTermStart.Value = DateMin;
            DTP_DialogSemesterSecondTermEnd.Value   = DateMin;

            DTP_DialogSemesterFirstTermStart.Enabled  = true;
            DTP_DialogSemesterFirstTermEnd.Enabled    = true;
            DTP_DialogSemesterSecondTermStart.Enabled = true;
            DTP_DialogSemesterSecondTermEnd.Enabled   = true;

            DTP_DialogSemesterFirstTermStart.Checked  = false;
            DTP_DialogSemesterFirstTermEnd.Checked    = false;
            DTP_DialogSemesterSecondTermStart.Checked = false;
            DTP_DialogSemesterSecondTermEnd.Checked   = false;
        }
Пример #10
0
        private void BTN_DialogReceipt_Add_Click(object sender, EventArgs e)
        {
            decimal amount;

            if (!ValidateInput.IsValid(TXT_DialogReceipt_Amount, true, out amount))
            {
                MessageBox.Show(null, "1. Amount must be valid\n\nRequired fields must be valid.", "Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }
            if (amount == 0)
            {
                MessageBox.Show(null, "1. Amount must not zero.\n\nRequired fields must be valid.", "Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }
            if ((balanceDue + amount) > 0)
            {
                MessageBox.Show(null, "1. Amount exceeds balance owing!\n\nPlease enter no more than required.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DialogResult = DialogResult.None;
                return;
            }
            Receipt receipt = new Receipt()
            {
                InvoiceId   = invoiceId,
                Amount      = amount,
                Misc        = TXT_DialogReceipt_Misc.Text,
                ReceiptDate = DateTime.Now.Date
            };

            // If validation successful
            if (cmd.AddReceipt(receipt))
            {
                mainForm.GetView("Transactions");
            }
        }
Пример #11
0
        // Add
        private void BTN_DialogAdminAdd_Click(object sender, EventArgs e)
        {
            bool   pass = true;
            string msg  = "";
            int    i    = 1;

            if (!ValidateInput.IsValid(TXT_DialogAdminFirstName))
            {
                pass = false;
                msg += i + ". First Name must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogAdminLastName))
            {
                pass = false;
                msg += i + ". Last Name must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogAdminEmail, true))
            {
                pass = false;
                msg += i + ". A valid Email address is required\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogAdminAddress))
            {
                pass = false;
                msg += i + ". Street Address must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogAdminCity))
            {
                pass = false;
                msg += i + ". City must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogAdminState))
            {
                pass = false;
                msg += i + ". State must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogAdminPostcode, @"^\d{4}$"))
            {
                pass = false;
                msg += i + ". Postcode must contain 4 digits only\n";
                i++;
            }
            if (!ValidateInput.IsValid(RADGRP_DialogAdminGender))
            {
                pass = false;
                msg += i + ". Gender must have a selection\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogAdminMobile))
            {
                pass = false;
                msg += i + ". Mobile number must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(DTP_DialogAdminDOB))
            {
                pass = false;
                msg += i + ". A Birthdate must be selected\n";
                i++;
            }
            if (!pass)
            {
                msg += "\nRequired fields must be valid.";
                MessageBox.Show(null, msg, "Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }

            string gender = RAD_DialogAdminGenderMale.Checked ? "Male" :
                            RAD_DialogAdminGenderFemale.Checked ? "Female" :
                            TXT_DialogAdminGender.Text == "Identify as..." ||
                            TXT_DialogAdminGender.Text == "" ? "Not Specified" :
                            TXT_DialogAdminGender.Text;

            Admin admin = new Admin()
            {
                UserEmail = TXT_DialogAdminEmail.Text,
                User      = new User()
                {
                    Email     = TXT_DialogAdminEmail.Text,        //"*****@*****.**",
                    FirstName = TXT_DialogAdminFirstName.Text,    //"Doug",
                    LastName  = TXT_DialogAdminLastName.Text,     //"DeGraves",
                    Address   = TXT_DialogAdminAddress.Text,      //"13 Life Close",
                    City      = TXT_DialogAdminCity.Text,         //"Rookwood",
                    State     = TXT_DialogAdminState.Text,        //"NSW",
                    Postcode  = TXT_DialogAdminPostcode.Text,     //"2141",
                    Gender    = gender,                           //"Male",
                    Mobile    = TXT_DialogAdminMobile.Text,       //"0400 666 666",
                    Dob       = DTP_DialogAdminDOB.Value.Date,    //new DateTime(1966, 6, 6),
                    Pass      = TXT_DialogAdminPassword.Text      //"ddeg"
                }
            };

            // If validation successful
            if (editUpdate)
            {
                cmd.UpdateUser(admin.User);
                mainForm.GetView("Administrators");
            }
            else
            {
                cmd.AddUser(admin);
                mainForm.GetView("Administrators");
            }
        }
Пример #12
0
        private void BTN_DialogCollegeAdd_Click(object sender, EventArgs e)
        {
            bool   pass = true;
            string msg  = "";
            int    i    = 1;

            if (!ValidateInput.IsValid(TXT_DialogCollegeName))
            {
                pass = false;
                msg += i + ". Name must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogCollegeAddress))
            {
                pass = false;
                msg += i + ". Street Address must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogCollegeCity))
            {
                pass = false;
                msg += i + ". City must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogCollegeState))
            {
                pass = false;
                msg += i + ". State must not be blank\n";
                i++;
            }
            if (!ValidateInput.IsValid(TXT_DialogCollegePostcode, @"^\d{4}$"))
            {
                pass = false;
                msg += i + ". Postcode must contain 4 digits only\n";
                i++;
            }
            if (!pass)
            {
                msg += "\nRequired fields must be valid.";
                MessageBox.Show(null, msg, "Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }
            // If validation successful
            if (editUpdate)
            {
                College college = new College()
                {
                    Id       = int.Parse(LBL_DialogCollegeId.Text),
                    Name     = TXT_DialogCollegeName.Text,
                    Address  = TXT_DialogCollegeAddress.Text,
                    City     = TXT_DialogCollegeCity.Text,
                    State    = TXT_DialogCollegeState.Text,
                    Postcode = TXT_DialogCollegePostcode.Text
                };
                if (cmd.UpdateCollege(college))
                {
                    mainForm.GetView("Colleges");
                }
            }
            else
            {
                College college = new College()
                {
                    Name     = TXT_DialogCollegeName.Text,
                    Address  = TXT_DialogCollegeAddress.Text,
                    City     = TXT_DialogCollegeCity.Text,
                    State    = TXT_DialogCollegeState.Text,
                    Postcode = TXT_DialogCollegePostcode.Text
                };
                if (cmd.AddCollege(college))
                {
                    mainForm.GetView("Colleges");
                }
            }
        }
        private void BTN_DialogSemesterAdd_Click(object sender, EventArgs e)
        {
            bool   pass = true;
            string msg  = "";
            int    i    = 1;

            if (!ValidateInput.IsValid(CMB_DialogSemesterYear))
            {
                pass = false;
                msg += i + ". A year must be selected\n";
                i++;
            }
            if (!ValidateInput.IsValid(CMB_DialogSemesterSemester))
            {
                pass = false;
                msg += i + ". A semester must be selected\n";
                i++;
            }
            if (!ValidateInput.IsValid(DTP_DialogSemesterFirstTermStart))
            {
                pass = false;
                msg += i + ". First term start date must be selected\n";
                i++;
            }
            if (!ValidateInput.IsValid(DTP_DialogSemesterFirstTermEnd))
            {
                pass = false;
                msg += i + ". First term end date must be selected\n";
                i++;
            }
            if (ValidateInput.IsValid(DTP_DialogSemesterFirstTermStart) &&
                ValidateInput.IsValid(DTP_DialogSemesterFirstTermEnd) &&
                !ValidateInput.IsValid(DTP_DialogSemesterFirstTermStart, DTP_DialogSemesterFirstTermEnd))
            {
                pass = false;
                msg += i + ". First term end date must be after start date\n";
                i++;
            }
            if (!ValidateInput.IsValid(DTP_DialogSemesterSecondTermStart))
            {
                pass = false;
                msg += i + ". Second term start date must be selected\n";
                i++;
            }
            if (ValidateInput.IsValid(DTP_DialogSemesterFirstTermEnd) &&
                ValidateInput.IsValid(DTP_DialogSemesterSecondTermStart) &&
                !ValidateInput.IsValid(DTP_DialogSemesterFirstTermEnd, DTP_DialogSemesterSecondTermStart))
            {
                pass = false;
                msg += i + ". Second term start date must be after first term\n";
                i++;
            }
            if (!ValidateInput.IsValid(DTP_DialogSemesterSecondTermEnd))
            {
                pass = false;
                msg += i + ". Second term end date must be selected\n";
                i++;
            }
            if (ValidateInput.IsValid(DTP_DialogSemesterSecondTermStart) &&
                ValidateInput.IsValid(DTP_DialogSemesterSecondTermEnd) &&
                !ValidateInput.IsValid(DTP_DialogSemesterSecondTermStart, DTP_DialogSemesterSecondTermEnd))
            {
                pass = false;
                msg += i + ". Second term end date must be after start date\n";
                i++;
            }
            if (!pass)
            {
                msg += "\nRequired fields must be valid.";
                MessageBox.Show(null, msg, "Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }
            Semester semester = new Semester()
            {
                Year            = new DateTime((int)CMB_DialogSemesterYear.SelectedItem, 1, 1),
                SecondSemester  = ((int)CMB_DialogSemesterSemester.SelectedItem).Equals(2),
                FirstTermBegin  = DTP_DialogSemesterFirstTermStart.Value.Date,
                FirstTermEnd    = DTP_DialogSemesterFirstTermEnd.Value.Date,
                SecondTermBegin = DTP_DialogSemesterSecondTermStart.Value.Date,
                SecondTermEnd   = DTP_DialogSemesterSecondTermEnd.Value.Date
            };
            IMainDAL cmd = new MainDAL();

            // If validation successful
            if (editUpdate)
            {
                if (cmd.UpdateSemester(semester))
                {
                    mainForm.GetView("Semesters");
                }
            }
            else
            {
                if (cmd.AddSemester(semester))
                {
                    mainForm.GetView("Semesters");
                }
            }
        }