Example #1
0
        //this will take from the textboxes and put it into the object
        private void PutPackageData(Package package)
        {
            try
            {
                if (Validator1.IsProvided(txtPkgName, "Package Name") &&
                    Validator1.IsProvided(txtPkgDesc, "Package Description") &&
                    Validator1.IsNonNegativeDecimal(txtPkgBasePrice, "Package Base Price") &&
                    Validator1.IsNonNegativeDecimal(txtPkgAgencyCommission, "Agency Commission"))
                {
                    package.PkgName = txtPkgName.Text;

                    if (dtStartDate.Value.Date >= dtEndDate.Value.Date)
                    {
                        MessageBox.Show("Package start date cannot be later than end date");
                    }
                    else if (dtStartDate.Value.ToString() == "" || dtEndDate.Value.ToString() == "")
                    {
                        MessageBox.Show("Please enter start and end date");
                    }
                    else if (Convert.ToDecimal(txtPkgBasePrice.Text) < Convert.ToDecimal(txtPkgAgencyCommission.Text))
                    {
                        MessageBox.Show("Agency Comission cannot be more than Package Base price!");
                    }
                    else
                    {
                        //Assigning all the given values to the package object
                        package.PkgStartDate        = dtStartDate.Value.ToString("yyyy-MM-dd");
                        package.PkgEndDate          = dtEndDate.Value.ToString("yyyy-MM-dd");
                        package.PkgDesc             = txtPkgDesc.Text;
                        package.PkgBasePrice        = Convert.ToDecimal(txtPkgBasePrice.Text);
                        package.PkgAgencyCommission = Convert.ToDecimal(txtPkgAgencyCommission.Text);

                        if (cboProdList.SelectedIndex < 00000000)
                        {
                            selectedProduct   = null;
                            product.ProductId = selectedProduct;
                        }
                        else
                        {
                            selectedProduct   = (int)cboProdList.SelectedItem;
                            product.ProductId = selectedProduct;
                        }

                        package.PackageId = PackageDB.AddNewPackage(package);
                        this.DialogResult = DialogResult.OK;
                        txtPackageId.Text = Convert.ToString(package.PackageId);
                        MessageBox.Show("Package has been saved");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
        private void PutSupplierData(Supplier newsupplier)
        {
            try
            {
                if (Validator1.IsProvided(txtSupId, "Supplier Id") &&
                    Validator1.IsProvided(txtSupName, "Supplier Name") &&
                    Validator1.IsNonNegativeDecimal(txtSupId, "Supplier Id"))
                {
                    supplier.SupplierId = Convert.ToInt32(txtSupId.Text);
                    supplier.SupName    = txtSupName.Text.ToString();

                    SuppliersDB.AddNewSupplier(supplier);

                    this.DialogResult = DialogResult.OK;
                    MessageBox.Show("Supplier has been saved");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }