private Grid InitOptCustomHelper(Food f, OptCustom options, int nRow, int rowNumber) { Grid cus = new Grid(); cus.Width = double.NaN; cus.Height = options.Options.Length * 20; cus.Margin = new Thickness(10, 10, 10, 10); cus.DataContext = f; cus.SetValue(Grid.RowProperty, rowNumber); int counter = 0; foreach (Option option in options.Options) { RowDefinition r = new RowDefinition(); r.Height = new GridLength(1, GridUnitType.Star); cus.RowDefinitions.Add(r); CheckBox b = new CheckBox(); b.DataContext = options; b.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler(CheckBoxClicked)); b.SetValue(Grid.RowProperty, counter); b.Content = option.Name; cus.Children.Add(b); counter += 1; } while (counter < rowNumber) { RowDefinition r = new RowDefinition(); r.Height = new GridLength(1, GridUnitType.Star); cus.RowDefinitions.Add(r); } return(cus); }
public static OptCustom Clone(OptCustom reqCustom) { OptCustom result = new OptCustom(reqCustom.Name); result.Options = new Option[reqCustom.Options.Length]; for (int i = 0; i < reqCustom.Options.Length; i++) { result.Options[i] = Option.Clone(reqCustom.Options[i]); } result.SelectedCount = reqCustom.SelectedCount; return(result); }
public static Food Clone(Food food) { Food result = new Food(food.Name, food.Price, food.Desciption); result.OptionCount = food.OptionCount; result.RequiredCustom = new ReqCustom[food.RequiredCustom.Length]; for (int i = 0; i < food.RequiredCustom.Length; i++) { result.RequiredCustom[i] = ReqCustom.Clone(food.RequiredCustom[i]); } result.OptionalCustom = new OptCustom[food.OptionalCustom.Length]; for (int i = 0; i < food.OptionalCustom.Length; i++) { result.OptionalCustom[i] = OptCustom.Clone(food.OptionalCustom[i]); } return(result); }
//Init price private ScrollViewer InitCustomOptions(Food f) { ScrollViewer sc = new ScrollViewer(); sc.Margin = new Thickness(10, 10, 10, 10); sc.SetValue(Grid.RowProperty, 1); sc.SetValue(Grid.ColumnProperty, 0); sc.VerticalAlignment = VerticalAlignment.Bottom; sc.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; Grid scg = new Grid(); sc.Content = scg; sc.Height = f.OptionCount * 20; ColumnDefinition c1 = new ColumnDefinition(); c1.Width = new GridLength(1, GridUnitType.Star); scg.ColumnDefinitions.Add(c1); ColumnDefinition c2 = new ColumnDefinition(); c2.Width = new GridLength(1, GridUnitType.Star); scg.ColumnDefinitions.Add(c2); StackPanel sp1 = new StackPanel(); sp1.SetValue(Grid.ColumnProperty, 0); scg.Children.Add(sp1); StackPanel sp2 = new StackPanel(); sp2.SetValue(Grid.ColumnProperty, 1); scg.Children.Add(sp2); for (int i = 0; i < f.RequiredCustom.Length + f.OptionalCustom.Length; i += 2) { if (i == f.RequiredCustom.Length + f.OptionalCustom.Length - 1) { if (i >= f.RequiredCustom.Length) { Grid g = InitOptCustomHelper(f, f.OptionalCustom[i - f.RequiredCustom.Length], f.OptionalCustom[i - f.RequiredCustom.Length].Options.Length, i / 2 + 1); sp1.Children.Add(g); } else { Grid g = InitReqCustomHelper(f, f.RequiredCustom[i], f.RequiredCustom[i].Options.Length, i / 2 + 1, f.Name + " " + i); sp1.Children.Add(g); } } else { int row = 0; if (f.RequiredCustom.Length == 0 || i >= f.RequiredCustom.Length) { OptCustom left = f.OptionalCustom[i - f.RequiredCustom.Length]; OptCustom right = f.OptionalCustom[i + 1 - f.RequiredCustom.Length]; int nRow = left.Options.Length > right.Options.Length ? left.Options.Length : right.Options.Length; Grid g1 = InitOptCustomHelper(f, left, nRow, row); sp1.Children.Add(g1); Grid g2 = InitOptCustomHelper(f, right, nRow, row); sp2.Children.Add(g2); } else if (f.OptionalCustom.Length == 0 || i < f.RequiredCustom.Length - 1) { ReqCustom left = f.RequiredCustom[i]; ReqCustom right = f.RequiredCustom[i + 1]; int nRow = left.Options.Length > right.Options.Length ? left.Options.Length : right.Options.Length; Grid g1 = InitReqCustomHelper(f, left, nRow, row, f.Name + " " + i); sp1.Children.Add(g1); Grid g2 = InitReqCustomHelper(f, right, nRow, row, f.Name + " " + i); sp2.Children.Add(g2); } else { ReqCustom left = f.RequiredCustom[i]; OptCustom right = f.OptionalCustom[i + 1 - f.RequiredCustom.Length]; int nRow = left.Options.Length > right.Options.Length ? left.Options.Length : right.Options.Length; Grid g1 = InitReqCustomHelper(f, left, nRow, row, f.Name + " " + i); sp1.Children.Add(g1); Grid g2 = InitOptCustomHelper(f, right, nRow, row); sp2.Children.Add(g2); } row += 2; } } return(sc); }