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 IngredientSet GetIngredientSet(int id, out bool cachedAdd, out bool cachedChange, out bool cachedRemove) { cachedAdd = false; cachedChange = false; cachedRemove = false; foreach (IngredientSet ingredientSet in _ingredientSetsAdded) { if (ingredientSet.Id == id) { cachedAdd = true; return(ingredientSet); } } foreach (IngredientSet ingredientSet in _ingredientSetsNeedingUpdate) { if (ingredientSet.Id == id) { cachedChange = true; return(ingredientSet); } } foreach (IngredientSet ingredientSet in _ingredientSetsRemoved) { if (ingredientSet.Id == id) { cachedRemove = true; return(ingredientSet); } } return(IngredientSet.Get(id)); }
private static void AddIngredientPreparation(int ingredientId, double amount) { foreach (IngredientSet ingredientSet in IngredientSet.GetAll(ingredientId)) { Ingredient ingredient = Ingredient.Get(ingredientSet.IngredientId); ingredient.SetInventoryAmount(ingredient.InventoryAmount - amount); ingredient.Update(); } }
private void AddIngredientSetToListBox(IngredientSet setIngredient, Ingredient ingredient) { string tagLine = ingredient.FullName + Environment.NewLine + Types.Strings.IngredientEditorAmount + FormatDoubleToString(setIngredient.Amount) + " " + setIngredient.MeasurementUnit + (Math.Abs(setIngredient.Amount - 1) < double.Epsilon ? "" : Types.Strings.S); listBoxItemIngredients.Items.Add( new FormattedListBoxItem(setIngredient.Id, tagLine, true)); }
private void buttonDecreaseInventory_Click(object sender, RoutedEventArgs e) { if (!IngredientSet.HasEntries(ActiveIngredient.Id)) { AdjustInventory(Types.Strings.IngredientEditorDecreaseByAmount, -1); } else { AdjustInventoryByRecipe(Types.Strings.IngredientEditorDecreaseByRecipe, -1); } }
private void buttonDecreaseBy_Click(object sender, RoutedEventArgs e) { if (!IngredientSet.HasEntries(ActiveIngredient.Id)) { AdjustInventory(Strings.InventoryDecreaseByAmount, -1); } else { AdjustInventoryByRecipe(Strings.InventoryDecreaseByRecipe, -1); } UpdateListBoxItem(); }
private void InitializeFields() { int oldCount = listBoxItemIngredients.Items.Count; listBoxAvailableIngredients.Items.Clear(); listBoxItemIngredients.Items.Clear(); List <Ingredient> ingredients = new List <Ingredient>(Ingredient.GetAll()); if (ActiveIngredient != null) { foreach (IngredientSet setIngredient in IngredientSet.GetAll(ActiveIngredient.Id)) { bool added, changed, removed; IngredientSet current = GetIngredientSet(setIngredient.Id, out added, out changed, out removed); if (!removed) { Ingredient ingredient = Ingredient.Find(ingredients, setIngredient.IngredientId); AddIngredientSetToListBox( (changed ? current : setIngredient), ingredient); ingredients.Remove(ingredient); } } } // Note: Added ones have an ExtendedIngredientId of zero so GetAll (above) will not find them foreach (IngredientSet setIngredient in _ingredientSetsAdded) { Ingredient ingredient = Ingredient.Find(ingredients, setIngredient.IngredientId); AddIngredientSetToListBox(setIngredient, ingredient); ingredients.Remove(ingredient); } if (ActiveIngredient != null) { foreach (Ingredient ingredient in ingredients) { if ((ingredient.Id == ActiveIngredient.Id) || ActiveIngredient.ContainsIngredient(ingredient.Id)) { continue; } listBoxAvailableIngredients.Items.Add( new FormattedListBoxItem(ingredient.Id, ingredient.FullName, true)); } } SetReadOnly(); SetupButtons(); ProcessEvents(oldCount); }
public void Update(int activeIngredientId) { Ingredient ingredient = Ingredient.Get(activeIngredientId); // Yield if (ingredient.ExtendedIngredientYield != ExtendedIngredientYield) { IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredient.Id, ingredient.ExtendedIngredientYield, ExtendedIngredientYield, MeasurementUnit.None, -1); ingredient.UpdateExtendedIngredientYield(ExtendedIngredientYield); } // Added Ingredients foreach (IngredientSet ingredientSet in _ingredientSetsAdded) { ingredientSet.SetExtendedIngredientId(activeIngredientId); ingredientSet.Update(); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredientSet.IngredientId, null, ingredientSet.Amount, ingredientSet.MeasurementUnit, activeIngredientId); } // Changed Ingredients foreach (IngredientSet ingredientSet in _ingredientSetsNeedingUpdate) { IngredientSet original = IngredientSet.Get(ingredientSet.Id); double oldAmount = UnitConversion.Convert(original.Amount, original.MeasurementUnit, ingredientSet.MeasurementUnit); ingredientSet.Update(); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredientSet.IngredientId, oldAmount, ingredientSet.Amount, ingredientSet.MeasurementUnit, activeIngredientId); } // Removed Ingredients foreach (IngredientSet ingredientSet in _ingredientSetsRemoved) { IngredientSet original = IngredientSet.Get(ingredientSet.Id); IngredientSet.Delete(ingredientSet.Id); IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredientSet.IngredientId, original.Amount, null, original.MeasurementUnit, activeIngredientId); } _ingredientSetsAdded.Clear(); _ingredientSetsNeedingUpdate.Clear(); _ingredientSetsRemoved.Clear(); }
public void Cancel() { foreach (IngredientSet ingredientSet in _ingredientSetsAdded) { IngredientSet.Delete(ingredientSet.Id); } _extendedIngredientYield = _originalExtendedIngredientYield; _ingredientSetsAdded.Clear(); _ingredientSetsNeedingUpdate.Clear(); _ingredientSetsRemoved.Clear(); // Reset UI buttonYield.Text = (_extendedIngredientYield.HasValue ? _extendedIngredientYield.Value.ToString(CultureInfo.InvariantCulture) : "0"); InitializeFields(); }
private static List <IngredientSet> GetIngredientSets(IDataReader reader) { List <IngredientSet> ingredientSets = new List <IngredientSet>(); while (reader.Read()) { var ingredientSet = new IngredientSet { Id = reader.GetValueOrDefault <int>("pset_id"), Name = reader.GetValueOrDefault <string>("pset_name") }; ingredientSets.Add(ingredientSet); } return(ingredientSets); }
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 RemoveIngredientSet(int id) { bool added, changed, removed; IngredientSet ingredientSet = GetIngredientSet(id, out added, out changed, out removed); if (added) { _ingredientSetsAdded.Remove(ingredientSet); } if (changed) { _ingredientSetsNeedingUpdate.Remove(ingredientSet); } if (!added && !removed) { _ingredientSetsRemoved.Add(ingredientSet); } }
private void ProcessInventoryChangesForPrepIngredients(double originalAmount, double newAmount) { if ((Math.Abs(originalAmount - newAmount) < double.Epsilon) || !ActiveIngredient.ExtendedIngredientYield.HasValue) { return; } foreach (IngredientSet ingredientSet in IngredientSet.GetAll(ActiveIngredient.Id)) { Ingredient prepIngredient = Ingredient.Get(ingredientSet.IngredientId); double difference = newAmount - originalAmount; double amount = UnitConversion.Convert(ingredientSet.Amount, ingredientSet.MeasurementUnit, prepIngredient.MeasurementUnit) * difference / ActiveIngredient.ExtendedIngredientYield.Value; prepIngredient.SetInventoryAmount(prepIngredient.InventoryAmount - amount); prepIngredient.Update(); if (ModifiedIngredient != null) { ModifiedIngredient.Invoke(prepIngredient, new EventArgs()); } } }
}// --> View public static void SetDataReference(IngredientSet Ingredients, RecipeSet Recipes, UnitSet Units) { _Ingredients = Ingredients; _Recipes = Recipes; _Units = Units; }
private void comboBoxMeasuringUnits_SelectedIndexChanged(object sender, EventArgs e) { MeasurementUnit oldUnit = MeasurementUnit; string text = comboBoxMeasuringUnits.SelectedItem; if (text == null) { MeasurementUnit = MeasurementUnit.None; } else { switch (comboBoxMeasuringUnits.SelectedIndex) { case 0: MeasurementUnit = MeasurementUnit.Unit; break; case 1: MeasurementUnit = MeasurementUnit.Pound; break; case 2: MeasurementUnit = MeasurementUnit.Ounce; break; case 3: MeasurementUnit = MeasurementUnit.Gram; break; case 4: MeasurementUnit = MeasurementUnit.Kilogram; break; case 5: MeasurementUnit = MeasurementUnit.Milligram; break; case 6: MeasurementUnit = MeasurementUnit.Gallon; break; case 7: MeasurementUnit = MeasurementUnit.Quart; break; case 8: MeasurementUnit = MeasurementUnit.Pint; break; case 9: MeasurementUnit = MeasurementUnit.Cup; break; case 10: MeasurementUnit = MeasurementUnit.Tablespoon; break; case 11: MeasurementUnit = MeasurementUnit.Teaspoon; break; case 12: MeasurementUnit = MeasurementUnit.Liter; break; case 13: MeasurementUnit = MeasurementUnit.FluidOunce; break; case 14: MeasurementUnit = MeasurementUnit.Milliliter; break; case 15: MeasurementUnit = MeasurementUnit.Kiloliter; break; } } if ((oldUnit != MeasurementUnit) && (MeasurementUnit != MeasurementUnit.Unit) && (MeasurementUnit != MeasurementUnit.None) && ((oldUnit.IsVolume() && MeasurementUnit.IsVolume()) || (oldUnit.IsWeight() && MeasurementUnit.IsWeight())) && PosDialogWindow.ShowDialog( Types.Strings.IngredientEditorConvert1 + (IngredientSet.HasEntries(ActiveIngredient.Id) ? Types.Strings.IngredientEditorConvert2 : "") + Types.Strings.IngredientEditorConvert3, Types.Strings.IngredientEditorUpdateInventory, DialogButtons.YesNo) == DialogButton.Yes) { InventoryAmount = UnitConversion.Convert(InventoryAmount, oldUnit, MeasurementUnit); textBoxInventoryAmount.Text = FormatDoubleToString(InventoryAmount); if (UnitsChanged != null) { UnitsChanged.Invoke(MeasurementUnit, new EventArgs()); } } else { if (UnitsChanged != null) { UnitsChanged.Invoke(MeasurementUnit, null); } } // Events DoValueChangedEvent(); }