/// <summary>
 /// event after commission field is validated
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tbxPkgCommission_Validating(object sender, CancelEventArgs e)
 {
     if (!PackageValidator.IsValidCommission((TextBox)sender, tbxPkgPrice))
     {
         e.Cancel = true;
     }
 }
 //clears all error providor messages on form.
 private void ClearFormErrors()
 {
     foreach (Control control in pnlPackage.Controls)
     {
         PackageValidator.ClearErrors(control);
     }
 }
 /// <summary>
 /// event occurs when price is being validated
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tbxPkgPrice_Validating(object sender, CancelEventArgs e)
 {
     if (!PackageValidator.IsValidMonetaryValue((TextBox)sender))
     {
         e.Cancel = true;
     }
 }
        /// <summary>
        /// Add a product to the package
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="supplierId"></param>
        private void AddProductToPackage(int productId, int supplierId)
        {
            try
            {
                //get the productsupplier from db
                ProductSupplier productSupplier = ProductSupplierDB.GetProductSupplier(productId, supplierId);

                //create the PPS to be added to db
                PackageProductSupplier newPackagePS = new PackageProductSupplier()
                {
                    ProductSupplierId = productSupplier.ProductSupplierID,
                    PackageId         = PackageSelected.PackageId
                };

                if (!PackageValidator.IsPackageProductSupplierExisting(newPackagePS))
                {
                    //add packageproductsupplier to db
                    PackageProductSupplierDB.Add(newPackagePS);
                    GetBindedPackageProducts(PackageSelected.PackageId);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Unable to add product", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Event occurs when an end date is selected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dtpPkgEndDate_ValueChanged(object sender, EventArgs e)
        {
            bool validDate = PackageValidator.IsValidEndDate((DateTimePicker)sender, dtpPkgStartDate.Value);

            if (validDate)
            {
                SetEndDate();
            }
        }
        /// <summary>
        /// validated a input string field and sets the errorprovidor on errors
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void ValidateString(object sender, CancelEventArgs e)
        {
            int maxCharCount = 50;

            if (!PackageValidator.IsValidString((TextBox)sender, maxCharCount))
            {
                e.Cancel = true;
            }
        }
Example #7
0
        /// <summary>
        /// Event occurs when an end date is selected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dtpPkgEndDate_ValueChanged(object sender, EventArgs e)
        {
            bool validDate = PackageValidator.IsValidEndDate((DateTimePicker)sender, dtpPkgStartDate.Value);

            //date not valid, return
            if (!validDate)
            {
                return;
            }
            else //date valid, updated data
            {
                SetEndDate((DateTimePicker)sender);
            }
        }
        /// <summary>
        /// validates a new package
        /// </summary>
        /// <returns></returns>
        private bool ValidateNewProduct()
        {
            bool validDesc       = PackageValidator.IsValidString(tbxPkgDesc, 50);
            bool validName       = PackageValidator.IsValidString(tbxPkgName, 50);
            bool validEndDate    = PackageValidator.IsValidEndDate(dtpPkgEndDate, dtpPkgStartDate.Value);
            bool validCommission = PackageValidator.IsValidCommission(tbxPkgCommission, tbxPkgPrice);
            bool validPrice      = PackageValidator.IsValidPrice(tbxPkgPrice);

            if (validDesc && validName && validEndDate && validCommission && validPrice)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #9
0
        /// <summary>
        /// Add a product to the package
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="supplierId"></param>
        private void AddProductToPackage(int productId, int supplierId)
        {
            //get the productsupplier from db
            ProductSupplier productSupplier = ProductSupplierDB.GetProductSupplier(productId, supplierId);

            //create the PPS to be added to db
            PackageProductSupplier newPackagePS = new PackageProductSupplier()
            {
                ProductSupplierId = productSupplier.ProductSupplierID,
                PackageId         = PackageSelected.PackageId
            };

            if (!PackageValidator.IsPackageProductSupplierExisting(newPackagePS))
            {
                //add packageproductsupplier to db
                PackageProductSupplierDB.Add(newPackagePS);

                GetBindedPackageProducts(PackageSelected.PackageId);
            }
        }