Esempio n. 1
0
 //Button click executes AddProduct method.
 private void Btn_Confirm(object sender, RoutedEventArgs e)
 {
     //Validation for Product properties.
     if (ValidateProduct.Validate(apvm.Product))
     {
         apvm.AddProduct();
         ManagerWindow window = new ManagerWindow();
         window.Show();
         this.Close();
     }
 }
 //Button click executes EditProduct method.
 private void Btn_Confirm(object sender, RoutedEventArgs e)
 {
     //Validation for Product properties.
     if (ValidateProduct.Validate(epvm.Product))
     {
         if (IsStored.IsChecked == false)
         {
             Checked = false;
         }
         epvm.EditProduct();
         ManagerWindow window = new ManagerWindow();
         window.Show();
         this.Close();
     }
 }
Esempio n. 3
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            LinqToSqlDataContext db = DatabaseSetup.Database;

            try
            {
                string   name         = ValidateProduct.Name(tbName.Text);
                int      quantity     = ValidateProduct.Quantity(tbQuantity.Text);
                string   unitName     = cbUnit.Text;
                decimal  unitQuantity = ValidateProduct.UnitQuantity(tbUnitQuantity.Text);
                DateTime?date         = ValidateProduct.Date(dpExpirationDate.SelectedDate);

                decimal price = ValidateProduct.Price(tbPrice.Text);
                price = Convert.ToDecimal(Math.Round(Convert.ToDouble(price), 1, MidpointRounding.AwayFromZero));
                bool priceForUnit = cbPriceForUnit.Text == "Ano" ? true : false;
                char VAT          = cbVAT.SelectedItem.ToString()[0];

                Product selectedProduct = (from p in db.Products
                                           where p.id == this._id
                                           select p).Single();

                int code = ValidateProduct.Code(tbCode.Text, selectedProduct.code);


                int uId = (from u in db.Units
                           where u.name == unitName
                           select u.id).Single();

                selectedProduct.name           = name;
                selectedProduct.quantity       = quantity;
                selectedProduct.unit           = uId;
                selectedProduct.unitQuantity   = unitQuantity;
                selectedProduct.expirationDate = date;
                selectedProduct.code           = code;
                selectedProduct.price          = price;
                selectedProduct.priceForUnit   = priceForUnit;
                selectedProduct.vatId          = VAT;

                db.SubmitChanges();
                DialogHelper.ShowInfo("Produkt byl upraven.");
                btnSubmit.IsEnabled = false;
            }
            catch (InvalidNameException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (InvalidQuantityException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (InvalidUnitQuantityException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (ExistingCodeException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (InvalidCodeException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }

            catch (InvalidPriceException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (NullDateTimeException ex)
            {
                DialogHelper.ShowError(ex.Message);
            }
            catch (Exception ex)
            {
                Errors.SaveError(ex.Message);
                DialogHelper.ShowError("Některé z polí není správně vyplněno.");
            }
        }
Esempio n. 4
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string   name         = ValidateProduct.Name(tbName.Text);
                int      quantity     = ValidateProduct.Quantity(tbQuantity.Text);
                string   unitName     = cbUnit.Text;
                decimal  unitQuantity = ValidateProduct.UnitQuantity(tbUnitQuantity.Text);
                DateTime?date         = ValidateProduct.Date(dpExpirationDate.SelectedDate);
                int      code         = ValidateProduct.Code(tbCode.Text);
                decimal  price        = ValidateProduct.Price(tbPrice.Text);
                price = Convert.ToDecimal(Math.Round(Convert.ToDouble(price), 1, MidpointRounding.AwayFromZero)); // cena se zaokrouhlí na jedno desetinné místo
                bool priceForUnit = cbPriceForUnit.Text == "Ano" ? true : false;
                char VAT          = cbVAT.SelectedItem.ToString()[0];

                LinqToSqlDataContext db = DatabaseSetup.Database;
                int i = (from u in db.Units
                         where u.name == unitName
                         select u.id).Single();
                int unitId = i;

                if (StorageSetup.AddProduct(name, quantity, unitId, unitQuantity, date, code, price, priceForUnit, VAT))
                {
                    // ještě je potřeba uložit do databáze obrázky a asociovat je s produktem
                    Product lastAddedProduct = StorageSetup.GetLastAddedProduct();
                    if (gallery.lbContainer.HasItems)
                    {
                        foreach (ImageStruct istr in gallery.Images)
                        {
                            Images.AddImage(istr);
                            ImagesTable lastAddedImage = Images.FindLastAddedImage();
                            Images.AssignImageToProduct(lastAddedProduct, lastAddedImage);
                        }
                    }

                    DialogHelper.ShowInfo("Produkt přidán.");
                    this.Close();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            catch (InvalidNameException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (InvalidQuantityException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (InvalidUnitQuantityException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (ExistingCodeException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (InvalidCodeException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }

            catch (InvalidPriceException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (NullDateTimeException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch
            {
                DialogHelper.ShowError("Produkt nebylo možné přidat.");
            }
        }