private void buttonSet_Click(object sender, RoutedEventArgs e)
        {
            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(Strings.InventorySetAmount);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;

            control.Amount          = 0;
            control.MeasurementUnit = ActiveIngredient.MeasurementUnit;

            window.ShowDialog(parent);
            if (!window.ClosedByUser)
            {
                if (control.Amount > 0)
                {
                    double amount = UnitConversion.Convert(control.Amount, control.MeasurementUnit,
                                                           ActiveIngredient.MeasurementUnit);

                    IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id,
                                             ActiveIngredient.InventoryAmount, amount, ActiveIngredient.MeasurementUnit);

                    ActiveIngredient.SetInventoryAmount(amount);
                    ActiveIngredient.Update();
                }
                UpdateListBoxItem();
            }
        }
        private void buttonYield_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(Types.Strings.IngredientEditorEditRecipeYield);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;

            control.MeasurementUnit = MeasurementUnit;
            control.Amount          = (ExtendedIngredientYield.HasValue ?
                                       ExtendedIngredientYield.Value : 0);

            window.ShowDialog(parent);
            if (!window.ClosedByUser)
            {
                double amount = 0;
                if (control.Amount > 0)
                {
                    amount = UnitConversion.Convert(control.Amount,
                                                    control.MeasurementUnit, MeasurementUnit);
                    _extendedIngredientYield = amount;
                }
                else
                {
                    _extendedIngredientYield = null;
                }
                buttonYield.Text   = amount.ToString(CultureInfo.InvariantCulture);
                labelUnits.Content = MeasurementUnit.ToString() +
                                     (Math.Abs(amount - 1) > double.Epsilon ? Types.Strings.S : "");
                if (YieldAmountChanged != null)
                {
                    YieldAmountChanged.Invoke(this, new EventArgs());
                }
                DoValueChangedEvent();
            }
            e.Handled = true;
        }
        private void AdjustInventory(string windowTitle, int factor)
        {
            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(windowTitle);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;

            control.Amount          = 0;
            control.MeasurementUnit = ActiveIngredient.MeasurementUnit;

            window.ShowDialog(parent);
            if (!window.ClosedByUser)
            {
                if (control.Amount > 0)
                {
                    double amount = UnitConversion.Convert(control.Amount, control.MeasurementUnit,
                                                           ActiveIngredient.MeasurementUnit) * factor;

                    IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id,
                                             ActiveIngredient.InventoryAmount,
                                             ActiveIngredient.InventoryAmount + amount,
                                             ActiveIngredient.MeasurementUnit);

                    ActiveIngredient.SetInventoryAmount(ActiveIngredient.InventoryAmount + amount);
                    ActiveIngredient.Update();
                }
            }
        }
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            FormattedListBoxItem selectedIngredient = (FormattedListBoxItem)
                                                      listBoxAvailableIngredients.SelectedItem;
            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(Types.Strings.IngredientEditorAddIngredient);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;
            Ingredient ingredient           = Ingredient.Get(selectedIngredient.Id);

            control.Amount          = 0;
            control.MeasurementUnit = ingredient.MeasurementUnit;

            window.ShowDialog(parent);
            if (window.ClosedByUser || (!(control.Amount > 0)))
            {
                return;
            }

            _ingredientSetsAdded.Add(
                IngredientSet.Add(0, selectedIngredient.Id,
                                  control.Amount, control.MeasurementUnit));
            listBoxAvailableIngredients.SelectedItem = null;
            listBoxItemIngredients.SelectedItem      = null;
            InitializeFields();
            DoValueChangedEvent();
        }
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            FormattedListBoxItem selectedItem =
                listBox.SelectedItem as FormattedListBoxItem;

            if (selectedItem == null)
            {
                return;
            }

            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(Strings.ItemEditorIngredientAmount);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;
            Ingredient ingredient           = Ingredient.Get(selectedItem.Id);

            control.Amount          = 0;
            control.MeasurementUnit = ingredient.MeasurementUnit;

            window.ShowDialog(parent);
            if (!window.ClosedByUser && (control.Amount > 0))
            {
                _itemIngredientsAdded.Add(
                    ItemIngredient.Add(0, selectedItem.Id, control.Amount,
                                       control.MeasurementUnit));
                InitializeFields();
                DoValueChangedEvent();
            }
        }
        private void buttonAmount_Click(object sender, RoutedEventArgs e)
        {
            FormattedListBoxItem selectedIngredient =
                listBoxItemIngredients.SelectedItem as FormattedListBoxItem;

            if (selectedIngredient == null)
            {
                return;
            }
            bool          added, changed, removed;
            IngredientSet ingredientSet = GetIngredientSet(selectedIngredient.Id,
                                                           out added, out changed, out removed);
            //Ingredient ingredient = Ingredient.Get(ingredientSet.IngredientId);

            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(Types.Strings.IngredientEditorEditAmount);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;

            control.Amount          = ingredientSet.Amount;
            control.MeasurementUnit = ingredientSet.MeasurementUnit;

            window.ShowDialog(parent);
            if (!window.ClosedByUser)
            {
                if (control.Amount > 0)
                {
                    ingredientSet.SetAmount(control.Amount);
                    ingredientSet.SetMeasurementUnit(control.MeasurementUnit);
                    if (!added && !changed)
                    {
                        _ingredientSetsNeedingUpdate.Add(ingredientSet);
                    }
                }
                else
                {
                    RemoveIngredientSet(ingredientSet.Id);
                    ResetYieldIfEmpty();
                }
                listBoxAvailableIngredients.SelectedItem = null;
                listBoxItemIngredients.SelectedItem      = null;
                InitializeFields();
                DoValueChangedEvent();
            }
        }
        private void AdjustInventory(string windowTitle, int factor)
        {
            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(windowTitle);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;

            control.Amount          = 0;
            control.MeasurementUnit = MeasurementUnit;

            window.ShowDialog(parent);
            if (!window.ClosedByUser)
            {
                if (control.Amount > 0)
                {
                    double amount = UnitConversion.Convert(control.Amount, control.MeasurementUnit,
                                                           ActiveIngredient.MeasurementUnit) * factor;
                    InventoryAmount            += amount;
                    textBoxInventoryAmount.Text = FormatDoubleToString(InventoryAmount);
                    DoValueChangedEvent();
                }
            }
        }
        private void buttonAmount_Click(object sender, RoutedEventArgs e)
        {
            FormattedListBoxItem selectedItem =
                (FormattedListBoxItem)listBoxItemIngredients.SelectedItem;
            bool           added = false, changed = false, removed = false;
            ItemIngredient itemIngredient = GetItemIngredient(selectedItem.Id,
                                                              out added, out changed, out removed);
            Ingredient ingredient = Ingredient.Get(itemIngredient.IngredientId);

            PosDialogWindow window = IngredientAmountControl
                                     .CreateInDefaultWindow(Strings.ItemEditorEditIngredient);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;

            control.Amount          = itemIngredient.Amount;
            control.MeasurementUnit = itemIngredient.MeasurementUnit;

            window.ShowDialog(parent);
            if (!window.ClosedByUser)
            {
                if (control.Amount > 0)
                {
                    itemIngredient.SetAmount(control.Amount);
                    itemIngredient.SetMeasurementUnit(control.MeasurementUnit);
                    if (!added && !changed)
                    {
                        _itemIngredientsNeedingUpdate.Add(itemIngredient);
                    }
                }
                else
                {
                    RemoveItemIngredient(selectedItem.Id);
                }
                listBox.SelectedItem = null;
                InitializeFields();
                DoValueChangedEvent();
            }
        }