private void btnUnitAdd_Click(object sender, RoutedEventArgs e) { try { string unitName = ValidateUnit.Name(tbUnitName.Text.Trim()); StorageSetup.AddUnit(unitName); // Refresh interface tbUnitName.Text = string.Empty; lbUnits.ItemsSource = StorageSetup.GetUnitNames(); } catch (ExistingUnitNameException ex) { DialogHelper.ShowWarning(ex.Message); } catch (UnitAddExcepton ex) { DialogHelper.ShowWarning(ex.Message); } catch (InvalidUnitNameException ex) { DialogHelper.ShowWarning(ex.Message); } catch { DialogHelper.ShowError("Při vkládání jednotky nastala nerozpoznaná chyba."); } }
/// <summary> /// Pokusí se přidat novou jednotku. V případě neúspěchu vrací false. /// </summary> /// <param name="name">Jméno nové jednotky</param> /// public static void AddUnit(string name) { LinqToSqlDataContext db = DatabaseSetup.Database; // Kontrola unikátnosti jména IEnumerable <string> allNames = StorageSetup.GetUnitNames(); foreach (string n in allNames) { if (n == name) { throw new ExistingUnitNameException(); } } Unit u = new Unit(); u.name = name; db.Units.InsertOnSubmit(u); try { db.SubmitChanges(); } catch (Exception ex) { Errors.SaveError(ex.Message); throw new UnitAddExcepton(); } }
private void btnDeleteAll_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Skutečně odstranit všechny výrobky?", "Varování", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { Storage.StorageSetup.DeleteAllProducts(); StorageSetup.InitializeStorageTable(dgStorage); DialogHelper.ShowInfo("Všechny produkty byly odstraněny."); } }
private void ShowStorageEditWindow(int ID) { EditProductWindow epw = new EditProductWindow(ID); epw.Owner = Window.GetWindow(this); epw.WindowStartupLocation = WindowStartupLocation.CenterOwner; epw.ShowInTaskbar = false; epw.ShowDialog(); StorageSetup.InitializeStorageTable(dgStorage); }
private void BtnRemoveImage_Click(object sender, RoutedEventArgs e) { int gonerId = gallery.GetSelectedImageDatabaseID(); ImagesTable gonerImage = Images.GetImageById(gonerId); // odstranit propojení Images.RemoveRelationship(gonerId, _id); // odstranit obrázek z databáze Images.RemoveImage(gonerId); //Refresh gallery gallery.Images = Images.GetImages(StorageSetup.GetProductById(_id)); gallery.Update(); }
private void btnAddProduct_Click(object sender, RoutedEventArgs e) { AddProductWindow apw = new AddProductWindow(); apw.Owner = Window.GetWindow(this); apw.WindowStartupLocation = WindowStartupLocation.CenterOwner; apw.ShowInTaskbar = false; if (StorageSetup.GetNumberOfUnits() == 0) { DialogHelper.ShowWarning("Podmínkou pro přidání výrobku je existence alespoň jedné jednotky." + Environment.NewLine + "Přidejte jí pomocí Správce jednotek."); } else { apw.ShowDialog(); } StorageSetup.InitializeStorageTable(dgStorage); }
private void btnDeleteProduct_Click(object sender, RoutedEventArgs e) { if (dgStorage.SelectedItem == null) { return; } StorageRecord record = (StorageRecord)dgStorage.SelectedItem; try { StorageSetup.DeleteProduct(record.id); DialogHelper.ShowError("Produkt byl odstraněn"); StorageSetup.InitializeStorageTable(dgStorage); } catch { DialogHelper.ShowError("Produkt nemohl být odstraněn"); } }
private void BtnAddImage_Click(object sender, RoutedEventArgs e) { // Nahrání obrázků do databáze System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Multiselect = true; ofd.Filter = "Obrázky|*.jpg;*.bmp;*.png;*.gif"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string[] paths = ofd.FileNames; Uri[] uris = new Uri[paths.Count()]; for (int i = 0; i <= paths.Count() - 1; i++) { uris[i] = new Uri(paths[i]); } List <ImageStruct> imagesAdded = new List <ImageStruct>(); for (int u = 0; u <= uris.Count() - 1; u++) { ImageStruct s = new ImageStruct() { imgName = System.IO.Path.GetFileNameWithoutExtension(paths[u]), image = new BitmapImage(uris[u]) }; imagesAdded.Add(s); } foreach (ImageStruct istr in imagesAdded) { // Práce s databází Images.AddImage(istr); Product p = StorageSetup.GetProductById(_id); ImagesTable imt = Images.FindLastAddedImage(); Images.AssignImageToProduct(p, imt); } // Získání obrázků z databáze - i s ID's gallery.Images = Images.GetImages(StorageSetup.GetProductById(_id)); gallery.Update(); } }
private void btnUnitRemove_Click(object sender, RoutedEventArgs e) { string unitGonerName = lbUnits.SelectedItem.ToString().Trim(); try { StorageSetup.RemoveUnit(unitGonerName); //Refresh interface lbUnits.ItemsSource = StorageSetup.GetUnitNames(); } catch (UnitInUseException ex) { DialogHelper.ShowWarning(ex.Message); } catch { DialogHelper.ShowError("Jednotka nemohla být odebrána"); } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Opravdu odstranit zvolený produkt (" + StorageSetup.GetProductFullName(StorageSetup.GetProductById(_id)) + ") ?", "Upozornění", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { try { StorageSetup.DeleteProduct(_id); DialogHelper.ShowInfo("Produkt byl odstraněn."); this.Close(); } catch (Exception ex) { Errors.SaveError(ex.Message); DialogHelper.ShowError("Produkt nemohl být odstraněn."); } } }
private void InitializeInterface() { cbPriceForUnit.Text = "Ne"; LinqToSqlDataContext db = DatabaseSetup.Database; IEnumerable <string> units = from u in db.Units select u.name.Trim(); cbUnit.ItemsSource = units; if (units.Count() > 0) { cbUnit.Text = units.First(); } cbVAT.ItemsSource = StorageSetup.GetVats(); if (cbVAT.Items.Count > 0) { cbVAT.Text = cbVAT.Items[0].ToString(); } btnSubmit.IsEnabled = false; // Změna v polích tbName.TextChanged += Method; tbQuantity.TextChanged += Method; tbUnitQuantity.TextChanged += Method; tbCode.TextChanged += Method; tbPrice.TextChanged += Method; cbPriceForUnit.SelectionChanged += Method; cbUnit.SelectionChanged += Method; dpExpirationDate.SelectedDateChanged += Method; cbVAT.SelectionChanged += Method; // Gallerie gallery.AddImageButton += BtnAddImage_Click; gallery.RemoveImageButton += BtnRemoveImage_Click; }
private void InitializeInterface() { LinqToSqlDataContext db = DatabaseSetup.Database; Product selectedProduct = (from p in db.Products where p.id == this._id select p).Single(); Unit selectedProductUnit = (from u in db.Units where u.id == selectedProduct.unit select u).Single(); tbName.Text = selectedProduct.name.Trim(); tbQuantity.Text = selectedProduct.quantity.ToString(); cbUnit.ItemsSource = StorageSetup.GetUnitNames(); cbUnit.Text = selectedProductUnit.name.Trim(); tbUnitQuantity.Text = selectedProduct.unitQuantity.ToString(); dpExpirationDate.SelectedDate = selectedProduct.expirationDate; tbCode.Text = selectedProduct.code.ToString(); cbPriceForUnit.Text = selectedProduct.priceForUnit == true ? "Ano" : "Ne"; tbPrice.Text = StorageSetup.GetFormattedMoney(Convert.ToDecimal(selectedProduct.price)); cbVAT.ItemsSource = StorageSetup.GetVats(); cbVAT.Text = StorageSetup.GetProductVat(selectedProduct); gallery.Images = Images.GetImages(selectedProduct); gallery.Update(); gallery.RemoveImageButton = BtnRemoveImage_Click; gallery.AddImageButton = BtnAddImage_Click; tbName.TextChanged += Method; tbQuantity.TextChanged += Method; tbUnitQuantity.TextChanged += Method; tbCode.TextChanged += Method; tbPrice.TextChanged += Method; cbPriceForUnit.SelectionChanged += Method; cbUnit.SelectionChanged += Method; dpExpirationDate.SelectedDateChanged += Method; cbVAT.SelectionChanged += Method; }
public static void InitializeStorageTable(DataGrid dataGrid) { LinqToSqlDataContext db = DatabaseSetup.Database; IEnumerable <StorageRecord> products = from p in db.Products join u in db.Units on p.unit equals u.id select new StorageRecord { id = p.id, name = StorageSetup.GetProductFullName(p), quantity = p.quantity, unit = u.name, unitQuantity = p.unitQuantity, expirationDate = GetFormattedString(p.expirationDate), price = GetFormattedMoneyCrowns(Convert.ToDecimal(p.price), p.priceForUnit, u.name), priceForUnit = p.priceForUnit == true ? "Ano" : "Ne", code = p.code, }; dataGrid.ItemsSource = products; }
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."); } }
private void InitializeInterface() { StorageSetup.InitializeStorageTable(dgStorage); }
private void InitializeInterface() { lbUnits.ItemsSource = StorageSetup.GetUnitNames(); }
/// <summary> /// Přidá testovací produkt do databáze. /// </summary> public static void AddDemoProducts() { StorageSetup.AddUnit("g"); // Kvůli cizímu klíči v Db LinqToSqlDataContext db = DatabaseSetup.Database; // DEMO PRODUCT1 ************************************* Product demoProduct = new Product(); demoProduct.name = "Rohlík tukový"; demoProduct.quantity = 100; demoProduct.expirationDate = DateTime.Now.AddDays(3); demoProduct.code = 1; demoProduct.price = 1.50m; demoProduct.unit = (from u in db.Units where u.name.Trim() == "g" select u.id).Single(); demoProduct.unitQuantity = 43.00m; demoProduct.priceForUnit = false; demoProduct.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct); // product1 images Images.AddImage("PASS.Images.roll.png", "Rohlík tukový obr.1"); Images.AddImage("PASS.Images.roll2.png", "Rohlík tukový obr.2"); // DEMO PRODUCT2 ************************************* StorageSetup.AddUnit("kg"); // Kvůli cizímu klíči v Db Product demoProduct2 = new Product(); demoProduct2.name = "Jablka červená"; demoProduct2.quantity = 1; demoProduct2.expirationDate = DateTime.Now.AddDays(30); demoProduct2.code = 2; demoProduct2.price = 17.90m; demoProduct2.unit = (from u in db.Units where u.name.Trim() == "kg" select u.id).Single(); demoProduct2.unitQuantity = 80.00m; demoProduct2.priceForUnit = true; demoProduct2.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct2); // Product 2 images Images.AddImage("PASS.Images.apple.png", "Jablko červené"); db.SubmitChanges(); Images.AssignImageToProduct(1, 1); Images.AssignImageToProduct(1, 2); Images.AssignImageToProduct(2, 3); //Demoproduct 3 StorageSetup.AddUnit("l"); // Kvůli cizímu klíči v Db Product demoProduct3 = new Product(); demoProduct3.name = "Mléko plnotučné trvanlivé"; demoProduct3.quantity = 20; demoProduct3.expirationDate = DateTime.Now.AddMonths(2); demoProduct3.code = 3; demoProduct3.price = 19.90m; demoProduct3.unit = (from u in db.Units where u.name.Trim() == "l" select u.id).Single(); demoProduct3.unitQuantity = 1.00m; demoProduct3.priceForUnit = false; demoProduct3.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct3); // Product 3 images Images.AddImage("PASS.Images.milk.png", "Mléko plnotučné trvanlivé"); db.SubmitChanges(); Images.AssignImageToProduct(3, 4); //Demoproduct 4 Product demoProduct4 = new Product(); demoProduct4.name = "Bramborový salát vážený"; demoProduct4.quantity = 1; demoProduct4.expirationDate = DateTime.Now.AddMonths(1); demoProduct4.code = 4; demoProduct4.price = 70.0m; demoProduct4.unit = (from u in db.Units where u.name.Trim() == "kg" select u.id).Single(); demoProduct4.unitQuantity = 8.00m; demoProduct4.priceForUnit = true; demoProduct4.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct4); // Product 4 images Images.AddImage("PASS.Images.salad.png", "Bramborový salát"); db.SubmitChanges(); Images.AssignImageToProduct(4, 5); //Demoproduct 5 Product demoProduct5 = new Product(); demoProduct5.name = "Chléb konzumní"; demoProduct5.quantity = 7; demoProduct5.expirationDate = DateTime.Now.AddDays(3); demoProduct5.code = 5; demoProduct5.price = 23.90m; demoProduct5.unit = (from u in db.Units where u.name.Trim() == "g" select u.id).Single(); demoProduct5.unitQuantity = 1200.00m; demoProduct5.priceForUnit = false; demoProduct5.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct5); // Product 5 images Images.AddImage("PASS.Images.bread.png", "Chléb konzumní"); db.SubmitChanges(); Images.AssignImageToProduct(5, 6); //Demoproduct 6 Product demoProduct6 = new Product(); demoProduct6.name = "Magnesia Perlivá přírodní minerální voda"; demoProduct6.quantity = 15; demoProduct6.expirationDate = DateTime.Now.AddMonths(12); demoProduct6.code = 6; demoProduct6.price = 23.90m; demoProduct6.unit = (from u in db.Units where u.name.Trim() == "l" select u.id).Single(); demoProduct6.unitQuantity = 1.50m; demoProduct6.priceForUnit = false; demoProduct6.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct6); // Product 6 images Images.AddImage("PASS.Images.magnesia.png", "Magnesia"); db.SubmitChanges(); Images.AssignImageToProduct(6, 7); //Demoproduct 7 Product demoProduct7 = new Product(); demoProduct7.name = "Bramborové hranolky"; demoProduct7.quantity = 9; demoProduct7.expirationDate = DateTime.Now.AddMonths(24); demoProduct7.code = 7; demoProduct7.price = 21.90m; demoProduct7.unit = (from u in db.Units where u.name.Trim() == "kg" select u.id).Single(); demoProduct7.unitQuantity = 1.00m; demoProduct7.priceForUnit = false; demoProduct7.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct7); // Product 7 images Images.AddImage("PASS.Images.chips.png", "Hranolky"); db.SubmitChanges(); Images.AssignImageToProduct(7, 8); //Demoproduct 8 Product demoProduct8 = new Product(); demoProduct8.name = "Pizza Ristorante Mozzarella"; demoProduct8.quantity = 12; demoProduct8.expirationDate = DateTime.Now.AddMonths(24); demoProduct8.code = 8; demoProduct8.price = 64.90m; demoProduct8.unit = (from u in db.Units where u.name.Trim() == "g" select u.id).Single(); demoProduct8.unitQuantity = 330.00m; demoProduct8.priceForUnit = false; demoProduct8.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct8); // Product 8 images Images.AddImage("PASS.Images.pizza.png", "Pizza"); db.SubmitChanges(); Images.AssignImageToProduct(8, 9); //Demoproduct 9 Product demoProduct9 = new Product(); demoProduct9.name = "Jacobs Velvet rozpustná 100% káva"; demoProduct9.quantity = 8; demoProduct9.expirationDate = DateTime.Now.AddMonths(24); demoProduct9.code = 9; demoProduct9.price = 150.00m; demoProduct9.unit = (from u in db.Units where u.name.Trim() == "g" select u.id).Single(); demoProduct9.unitQuantity = 200.00m; demoProduct9.priceForUnit = false; demoProduct9.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct9); // Product 9 images Images.AddImage("PASS.Images.coffee.png", "Jacobs Velvet káva"); db.SubmitChanges(); Images.AssignImageToProduct(9, 10); //Demoproduct 10 Product demoProduct10 = new Product(); demoProduct10.name = "Jihočeský jogurt jahoda"; demoProduct10.quantity = 10; demoProduct10.expirationDate = DateTime.Now.AddMonths(6); demoProduct10.code = 10; demoProduct10.price = 19.90m; demoProduct10.unit = (from u in db.Units where u.name.Trim() == "g" select u.id).Single(); demoProduct10.unitQuantity = 200.00m; demoProduct10.priceForUnit = false; demoProduct10.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct10); // Product 10 images Images.AddImage("PASS.Images.yoghurt.png", "Jogurt jahoda"); db.SubmitChanges(); Images.AssignImageToProduct(10, 11); //Demoproduct 11 Product demoProduct11 = new Product(); demoProduct11.name = "Pilsner Urquell Pivo ležák světlý"; demoProduct11.quantity = 40; demoProduct11.expirationDate = DateTime.Now.AddMonths(12); demoProduct11.code = 11; demoProduct11.price = 23.90m; demoProduct11.unit = (from u in db.Units where u.name.Trim() == "l" select u.id).Single(); demoProduct11.unitQuantity = 0.50m; demoProduct11.priceForUnit = false; demoProduct11.vatId = 'A'; db.Products.InsertOnSubmit(demoProduct11); // Product 11 images Images.AddImage("PASS.Images.pilsner.png", "Pilsner Urquell"); db.SubmitChanges(); Images.AssignImageToProduct(11, 12); //Demoproduct 12 Product demoProduct12 = new Product(); demoProduct12.name = "Předměřická mouka pšeničná"; demoProduct12.quantity = 50; demoProduct12.expirationDate = DateTime.Now.AddMonths(24); demoProduct12.code = 12; demoProduct12.price = 9.90m; demoProduct12.unit = (from u in db.Units where u.name.Trim() == "kg" select u.id).Single(); demoProduct12.unitQuantity = 1.00m; demoProduct12.priceForUnit = false; demoProduct12.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct12); // Product 12 images Images.AddImage("PASS.Images.flour.png", "Mouka pšeničná"); db.SubmitChanges(); Images.AssignImageToProduct(12, 13); //Demoproduct 13 Product demoProduct13 = new Product(); demoProduct13.name = "Pickwick Zelený čaj mango a jasmín"; demoProduct13.quantity = 30; demoProduct13.expirationDate = DateTime.Now.AddMonths(12); demoProduct13.code = 13; demoProduct13.price = 45.90m; demoProduct13.unit = (from u in db.Units where u.name.Trim() == "g" select u.id).Single(); demoProduct13.unitQuantity = 30.00m; demoProduct13.priceForUnit = false; demoProduct13.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct13); // Product 13 images Images.AddImage("PASS.Images.pickwick.png", "Pickwick Zelený čaj mango a jasmín"); db.SubmitChanges(); Images.AssignImageToProduct(13, 14); //Demoproduct 14 AddUnit("ml"); Product demoProduct14 = new Product(); demoProduct14.name = "Míša Jahodový "; demoProduct14.quantity = 20; demoProduct14.expirationDate = DateTime.Now.AddMonths(12); demoProduct14.code = 14; demoProduct14.price = 8.90m; demoProduct14.unit = (from u in db.Units where u.name.Trim() == "ml" select u.id).Single(); demoProduct14.unitQuantity = 45.00m; demoProduct14.priceForUnit = false; demoProduct14.vatId = 'B'; db.Products.InsertOnSubmit(demoProduct14); // Product 13 images Images.AddImage("PASS.Images.misa.png", "Míša Jahodový"); db.SubmitChanges(); Images.AssignImageToProduct(14, 15); }