Ejemplo n.º 1
0
        /// <summary>
        /// Updates the Package Fields displayed on the form
        /// </summary>
        /// <param name="package"></param>
        private bool DisplayPackage(int packageId)
        {
            //the package displayed is the same as the package selected from the drop down... do not redisplay.
            if (!Object.Equals(PackageSelected, null) && packageId == PackageSelected.PackageId && PackageSelected.PkgName == lblPackageName.Text)
            {
                return(false);
            }

            //get the package data
            PackageSelected = PackageDB.GetById(packageId);

            //Update non-nullable properties

            tbxPkgName.Text  = PackageSelected.PkgName.ToString();
            tbxPkgPrice.Text = Decimal.Round(PackageSelected.PkgBasePrice, 2).ToString();

            //Update nullable properties
            tbxPkgCommission.Text =
                (PackageSelected.PkgAgencyCommission.HasValue) ?
                Decimal.Round((decimal)PackageSelected.PkgAgencyCommission, 2).ToString() : String.Empty;

            tbxPkgDesc.Text = PackageSelected.PkgDesc.ToString();

            //start date is null, remove format
            if (Object.Equals(PackageSelected.PkgStartDate, null))
            {
                dtpPkgStartDate.CustomFormat = " ";
            }
            else
            {
                dtpPkgStartDate.CustomFormat = DateTimePickerFormat;
                dtpPkgStartDate.Text         = PackageSelected.PkgStartDate.ToString();
            }

            //end date is null, remove format
            if (Object.Equals(PackageSelected.PkgEndDate, null))
            {
                dtpPkgEndDate.CustomFormat = " ";
            }
            else
            {
                dtpPkgEndDate.CustomFormat = DateTimePickerFormat;
                dtpPkgEndDate.Text         = PackageSelected.PkgEndDate.ToString();
            }

            //update char count labels
            DisplayCharCount(tbxPkgDesc, lblDescCharCount);
            DisplayCharCount(tbxPkgName, lblNameCharCount);

            //If package name is updated, update controls
            if (PackageSelected.PkgName != lblPackageName.Text)
            {
                lblPackageName.Text = PackageSelected.PkgName.ToString();
                GetBindedPackageIds();
            }

            return(true);
        }
        /// <summary>
        /// Saves the newly created product from the form into the database
        /// </summary>
        private void SaveNewProduct()
        {
            if (!ValidateNewProduct())
            {
                return;
            }

            try
            {
                int     newPackageID = PackageDB.InsertPackage(GetPackageFromFields());
                Package package      = PackageDB.GetById(newPackageID);

                GetBindedPackageIds(newPackageID);
                DisplayPackageDetails(package);
                HideNewPackageLayout(newPackageID);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Updates the Package Fields displayed on the form
        /// </summary>
        /// <param name="package"></param>
        private bool DisplayPackage(int packageId, bool isNewPackage = false)
        {
            //the package displayed is the same as the package selected from the drop down... do not redisplay.
            if (!Object.Equals(PackageSelected, null) &&
                packageId == PackageSelected.PackageId &&
                PackageSelected.PkgName == lblPackageName.Text)
            {
                return(false);
            }

            if (isNewPackage)
            {
                PackageSelected = new Package()
                {
                    PackageId           = -1,
                    PkgAgencyCommission = null,
                    PkgBasePrice        = 0m,
                    PkgDesc             = "",
                    PkgEndDate          = DateTime.Today.AddDays(1),
                    PkgName             = "",
                    PkgStartDate        = DateTime.Today
                };
            }
            else
            {
                PackageSelected = PackageDB.GetById(packageId);  //get the package data
            }
            //Update properties
            tbxPkgName.Text
                = String.IsNullOrEmpty(PackageSelected.PkgName) ?
                  String.Empty : PackageSelected.PkgName.ToString();

            tbxPkgPrice.Text = Decimal.Round(PackageSelected.PkgBasePrice, 2).ToString();

            tbxPkgCommission.Text =
                (PackageSelected.PkgAgencyCommission.HasValue) ?
                Decimal.Round((decimal)PackageSelected.PkgAgencyCommission, 2).ToString() : String.Empty;

            tbxPkgDesc.Text = String.IsNullOrEmpty(PackageSelected.PkgDesc) ?
                              String.Empty : PackageSelected.PkgDesc.ToString();

            //start date is null, remove format
            if (Object.Equals(PackageSelected.PkgStartDate, null))
            {
                ShowEmptyDate(dtpPkgStartDate, true);
            }
            else
            {
                ShowEmptyDate(dtpPkgStartDate, false);
                dtpPkgStartDate.Text = PackageSelected.PkgStartDate.ToString();
            }

            //end date is null, remove format
            if (Object.Equals(PackageSelected.PkgEndDate, null))
            {
                ShowEmptyDate(dtpPkgEndDate, true);
            }
            else
            {
                ShowEmptyDate(dtpPkgEndDate, false);
                dtpPkgEndDate.Text = PackageSelected.PkgEndDate.ToString();
            }

            //update char count labels
            DisplayCharCount(tbxPkgDesc, lblDescCharCount);
            DisplayCharCount(tbxPkgName, lblNameCharCount);

            //If package name is updated, update related name controls ONLY
            if (PackageSelected.PkgName != lblPackageName.Text)
            {
                lblPackageName.Text = PackageSelected.PkgName.ToString();
            }

            return(true);
        }