示例#1
0
        private async void DeleteEditButton_Click(object sender, RoutedEventArgs e)
        {
            using (DBContext dBCtx = new DBContext())
            {
                if (!dBCtx.Categories.Any(x => x.CategoryID == CategoryTb.Text))
                {
                    Category category = dBCtx.Categories.Single(x => x.CategoryID == CategoryTb.Text);
                    string   errorMsg = InvMgt.isCategoryValid(category);
                    if (String.IsNullOrEmpty(errorMsg))
                    {
                        dBCtx.Categories.Remove(category);
                        dBCtx.SaveChanges();
                    }

                    else
                    {
                        MessageDialog message = new MessageDialog(errorMsg, "Operacja przerwana");
                        await message.ShowAsync();

                        return;
                    }
                }
            }
            this.Frame.Navigate(typeof(MainPage), "BackToCategoriesList");
        }
示例#2
0
        private async void SaveEditButton_Click(object sender, RoutedEventArgs e)
        {
            using (DBContext dBCtx = new DBContext())
            {
                if (!dBCtx.Categories.Any(x => x.CategoryID == CategoryTb.Text))
                {
                    Warehouse      warehouse      = (Warehouse)WarehouseCb.SelectedItem;
                    WarehousePlace warehousePlace = (WarehousePlace)WarehousePlaceCb.SelectedItem;

                    Category category = new Category(CategoryTb.Text, DescriptionTb.Text, warehouse.WarehouseName, warehousePlace.WarehousePlaceName);
                    string   errorMsg = InvMgt.isCategoryValid(category);
                    if (String.IsNullOrEmpty(errorMsg))
                    {
                        dBCtx.Categories.Add(category);
                        dBCtx.SaveChanges();
                    }
                    else
                    {
                        MessageDialog message = new MessageDialog(errorMsg, "Operacja przerwana");
                        await message.ShowAsync();

                        return;
                    }
                }
                else
                {
                    Warehouse      warehouse      = (Warehouse)WarehouseCb.SelectedItem;
                    WarehousePlace warehousePlace = (WarehousePlace)WarehousePlaceCb.SelectedItem;

                    Category category = dBCtx.Categories.Single(x => x.CategoryID == CategoryTb.Text);
                    dBCtx.Attach(category);
                    category.Description           = DescriptionTb.Text;
                    category.DefaultWarehouse      = warehouse.WarehouseName;
                    category.DefaultWarehousePlace = warehousePlace.WarehousePlaceName;
                    dBCtx.SaveChanges();
                }
                this.Frame.Navigate(typeof(MainPage), "BackToCategoriesList");
            }
        }