コード例 #1
0
ファイル: Custom.cs プロジェクト: sguan94/SimplyOrder
        public static ReqCustom Clone(ReqCustom reqCustom)
        {
            ReqCustom result = new ReqCustom(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.Selected = reqCustom.Selected;
            return(result);
        }
コード例 #2
0
ファイル: Food.cs プロジェクト: sguan94/SimplyOrder
        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);
        }
コード例 #3
0
        private Grid InitReqCustomHelper(Food f, ReqCustom options, int nRow, int rowNumber, string groupName)
        {
            Grid cus = new Grid();

            cus.Width  = double.NaN;
            cus.Height = options.Options.Length * 20;
            cus.Margin = new Thickness(10, 10, 10, 10);
            cus.SetValue(Grid.RowProperty, rowNumber);
            cus.DataContext = options;
            cus.DataContext = f;

            int counter = 0;

            foreach (Option option in options.Options)
            {
                RowDefinition r = new RowDefinition();
                r.Height = new GridLength(1, GridUnitType.Star);
                cus.RowDefinitions.Add(r);
                RadioButton b = new RadioButton();
                b.AddHandler(RadioButton.ClickEvent, new RoutedEventHandler(RadioButtonClicked));
                if (counter == 0)
                {
                    b.IsChecked = true;
                }
                b.SetValue(Grid.RowProperty, counter);
                b.GroupName   = groupName;
                b.DataContext = options;
                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);
        }
コード例 #4
0
        public OrderItem(Food food)
        {
            this.Food  = food;
            this.Count = 1;
            this.Price = Food.Price;
            this.Name  = Food.Name;

            for (int i = 0; i < Food.RequiredCustom.Length; i++)
            {
                ReqCustom curr = Food.RequiredCustom[i];
                this.Name += curr.Options[curr.Selected].Name;
            }
            for (int i = 0; i < Food.OptionalCustom.Length; i++)
            {
                foreach (Option option in Food.OptionalCustom[i].Options)
                {
                    if (option.Selected)
                    {
                        this.Name += option.Name;
                    }
                }
            }
        }
コード例 #5
0
        //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);
        }