Exemplo n.º 1
0
 private void btnAccept_Click_1(object sender, EventArgs e)
 {
     if (addPackage)
     {
         pack = new Packages();
         putPackageData(pack);
         int Id = PackagesDB.AddPackage(pack);
         MessageBox.Show("New Package with Id of" + Id + " was added");
         this.DialogResult = DialogResult.OK;
     }
     else
     {
         Packages newPackage = new Packages();
         newPackage.PackageId = modifyPack.PackageId;
         this.putPackageData(newPackage);
         try
         {
             if (!PackagesDB.UpdatePackage(modifyPack, newPackage))
             {
                 MessageBox.Show("Another user has updated or " +
                                 "deleted that customer.", "Database Error");
                 this.DialogResult = DialogResult.Retry;
             }
             else
             {
                 modifyPack        = newPackage;
                 this.DialogResult = DialogResult.OK;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
 }
        // button the add the data to the DB
        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (isValid())
            {
                if (add)
                {
                    package = this.createPackageObjects();
                    try
                    {
                        package.PackageId = PackagesDB.AddPackage(package);


                        foreach (Packages_Products_Suppliers ps in pack_prod_sup)
                        {
                            ps.PackageId = package.PackageId;
                            Packages_Products_SuppliersDB.AddPackProdSupp(ps);
                        }

                        this.DialogResult = DialogResult.OK;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
                else
                {
                    Package newPackage = new Package();
                    newPackage = this.createPackageObjects();

                    try
                    {
                        if (!PackagesDB.UpdatePackage(package, newPackage))
                        {
                            MessageBox.Show("That Package has been updated or deleted already.", "Database Error");
                            this.DialogResult = DialogResult.Retry;
                        }
                        else
                        {
                            package           = newPackage;
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
        private void btnAcceptEdit_Click(object sender, EventArgs e)
        {
            Packages currentPackage = PackagesDB.GetPackageById((int)id);
            Packages newPackage     = new Packages();
            bool     currentDates   = IsValidShippedDate();

            if (currentPackage.PkgName == null ||
                currentPackage.PkgDesc == null
                )
            {
                MessageBox.Show("Fill in name and description before adding package", "Please check");

                this.DialogResult = DialogResult.OK;
            }

            else if (Validator.IsPresent(txtPkgName) &&
                     Validator.IsPresent(txtPkgDesc) &&
                     Validator.IsDecimal(txtBasePrice) &&
                     Validator.IsDecimal(txtCommission) &&
                     currentDates == true)
            {
                newPackage.PackageId = currentPackage.PackageId;
                this.PutPackageData(newPackage);
                try
                {
                    if (!PackagesDB.UpdatePackage(currentPackage, newPackage))
                    {
                        MessageBox.Show("Another user has updated or " +
                                        "deleted that package.", "Database Error");
                        this.DialogResult = DialogResult.Retry;
                    }
                    else
                    {
                        package = newPackage;
                        MessageBox.Show("Package updated", "Success!");
                        this.DialogResult = DialogResult.OK;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
                this.Close();
            }
        }
Exemplo n.º 4
0
 private void btnAccept_Click(object sender, EventArgs e)
 {
     if (addPackage)
     {
         package = new Packages();
         this.PutPackageData(package);
         try
         {
             package.PackageId = PackagesDB.AddPackage(package);
             this.DialogResult = DialogResult.OK;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
     else
     {
         Packages newPackage = new Packages();
         newPackage.PackageId = package.PackageId;
         this.PutPackageData(newPackage);
         try
         {
             if (!PackagesDB.UpdatePackage(package, newPackage))
             {
                 MessageBox.Show("Another user has updated or " +
                                 "deleted that package.", "Database Error");
                 this.DialogResult = DialogResult.Retry;
             }
             else
             {
                 package           = newPackage;
                 this.DialogResult = DialogResult.OK;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
 }