private void btnConfirmPayment_Click(object sender, EventArgs e)
        {
            try
            {
                string errMsg = ValidateForm();
                if (errMsg != string.Empty)
                {
                    MessageBox.Show(errMsg, "Invalid Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    PaymentBL paymentBL = new PaymentBL();

                    Payment_Entity p = new Payment_Entity()
                    {
                        StudentId       = s.StudentId,
                        AmountOfPayment = Convert.ToDecimal(txtAmountOfPayment.Text),
                        Date            = DateTime.Now
                    };
                    if (paymentBL.MakePayment(p))
                    {
                        PopulateStudent(s.StudentId);
                        MessageBox.Show("Payment made!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public bool MakePayment(Payment_Entity p)
        {
            PaymentRepo repo = new PaymentRepo();

            if (IsValidEntity(p))
            {
                return(repo.makePayment(p));
            }
            return(false);
        }
        public bool makePayment(Payment_Entity p)
        {
            List <ParmStruct> parms = new List <ParmStruct>();

            parms.Add(new ParmStruct("@StudentId", p.StudentId, SqlDbType.NVarChar, ParameterDirection.Input, 8));
            parms.Add(new ParmStruct("@AmountOfPayment", p.AmountOfPayment, SqlDbType.SmallMoney, ParameterDirection.Input));
            parms.Add(new ParmStruct("@PaymentDate", p.Date, SqlDbType.DateTime, ParameterDirection.Input));


            DataAccess db = new DataAccess();

            return(db.ExecuteNonQuery("spMakePayment", CommandType.StoredProcedure, parms) > 0);
        }
        private bool IsValidEntity(Payment_Entity p)
        {
            ValidationContext       context = new ValidationContext(p);
            List <ValidationResult> results = new List <ValidationResult>();

            bool isValid = Validator.TryValidateObject(p, context, results, true);

            foreach (ValidationResult r in results)
            {
                Errors.Add(new ValidationError(r.ErrorMessage));
            }

            return(isValid);
        }