예제 #1
0
        private void definitievePrijs(TicketautomaatInvoer info)
        {
            // *************************************
            // This is the code you need to refactor
            // *************************************

            // Get number of tariefeenheden
            //int tariefeenheden = Database.getTariefeenheden(info.From, info.To);

            int tariefeenheden = Track.getTariefeenheden();

            // Compute the column in the table based on choices
            int tableColumn;

            // First based on class
            switch (info.Class)
            {
            case UIClass.FirstClass:
                tableColumn = 3;
                break;

            default:
                tableColumn = 0;
                break;
            }

            // Then, on the discount
            switch (info.Discount)
            {
            case UIDiscount.TwentyDiscount:
                tableColumn += 1;
                break;

            case UIDiscount.FortyDiscount:
                tableColumn += 2;
                break;
            }

            // Get price
            Prijsberekening P     = new Prijsberekening();
            float           price = P.getPrice(tariefeenheden, tableColumn);

            if (info.Way == UIWay.Return)
            {
                price *= 2;
            }
            // Add 50 cent if paying with credit card if the price is not 0
            if (info.From == info.To)
            {
                MessageBox.Show("Start location and destination are the same.");
                price = 0;
            }
            else if (info.Payment == UIPayment.CreditCard)
            {
                price += 0.50f;
            }

            // Methode betaling aanroepen
            betaling(info, price);
        }
예제 #2
0
        public void DefinitievePrijs(TicketautomaatInvoer info)
        {
            // Get number of tariefeenheden
            Database.AddTracks();
            tariefeenheden = Database.GetTariefeenheden(Database.alleTracks, info.From, info.To);

            // Get price
            GetClass(info);
            GetDiscount(info);
            Prijsberekening P     = new Prijsberekening();
            float           price = P.PriceColumn(tariefeenheden, tableColumn);

            CalcRetour(info, price);
            CreditCardFee(info, price);

            // Verwerken betaling
            Ticketautomaat t = new Ticketautomaat();

            t.VerwerkBetaling(info, price);
        }
예제 #3
0
        private void initializeControls()
        {
            // Set label
            this.Text = "MSO Lab Exercise III";
            // this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.Width  = 500;
            this.Height = 210;
            // Set layout
            var grid = new TableLayoutPanel();

            grid.Dock    = DockStyle.Fill;
            grid.Padding = new Padding(5);
            this.Controls.Add(grid);
            grid.RowCount = 4;
            grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 20));
            grid.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 20));
            grid.RowStyles.Add(new RowStyle(SizeType.Absolute, 40));
            grid.ColumnCount = 6;
            for (int i = 0; i < 6; i++)
            {
                ColumnStyle c = new ColumnStyle(SizeType.Percent, 16.66666f);
                grid.ColumnStyles.Add(c);
            }
            // Create From and To
            var fromLabel = new Label();

            fromLabel.Text      = "From:";
            fromLabel.TextAlign = ContentAlignment.MiddleRight;
            grid.Controls.Add(fromLabel, 0, 0);
            fromLabel.Dock        = DockStyle.Fill;
            fromBox               = new ComboBox();
            fromBox.DropDownStyle = ComboBoxStyle.DropDownList;
            fromBox.Items.AddRange(Database.GetStations());
            fromBox.SelectedIndex = 0;
            grid.Controls.Add(fromBox, 1, 0);
            grid.SetColumnSpan(fromBox, 2);
            fromBox.Dock = DockStyle.Fill;
            var toLabel = new Label();

            toLabel.Text      = "To:";
            toLabel.TextAlign = ContentAlignment.MiddleRight;
            grid.Controls.Add(toLabel, 3, 0);
            toLabel.Dock        = DockStyle.Fill;
            toBox               = new ComboBox();
            toBox.DropDownStyle = ComboBoxStyle.DropDownList;
            toBox.Items.AddRange(Database.GetStations());
            toBox.SelectedIndex = 0;
            grid.Controls.Add(toBox, 4, 0);
            grid.SetColumnSpan(toBox, 2);
            toBox.Dock = DockStyle.Fill;
            // Create groups
            GroupBox classGroup = new GroupBox();

            classGroup.Text = "Class";
            classGroup.Dock = DockStyle.Fill;
            grid.Controls.Add(classGroup, 0, 1);
            grid.SetColumnSpan(classGroup, 2);
            var classGrid = new TableLayoutPanel();

            classGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            classGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            classGrid.Dock = DockStyle.Fill;
            classGroup.Controls.Add(classGrid);
            GroupBox wayGroup = new GroupBox();

            wayGroup.Text = "Amount";
            wayGroup.Dock = DockStyle.Fill;
            grid.Controls.Add(wayGroup, 2, 1);
            grid.SetColumnSpan(wayGroup, 2);
            var wayGrid = new TableLayoutPanel();

            wayGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            wayGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            wayGrid.Dock = DockStyle.Fill;
            wayGroup.Controls.Add(wayGrid);
            GroupBox discountGroup = new GroupBox();

            discountGroup.Text = "Discount";
            discountGroup.Dock = DockStyle.Fill;
            grid.Controls.Add(discountGroup, 4, 1);
            grid.SetColumnSpan(discountGroup, 2);
            var discountGrid = new TableLayoutPanel();

            discountGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333f));
            discountGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333f));
            discountGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333f));
            discountGrid.Dock = DockStyle.Fill;
            discountGroup.Controls.Add(discountGrid);
            // Create radio buttons
            firstClass         = new RadioButton();
            firstClass.Text    = "1st class";
            firstClass.Checked = true;
            classGrid.Controls.Add(firstClass);
            secondClass      = new RadioButton();
            secondClass.Text = "2nd class";
            classGrid.Controls.Add(secondClass);
            oneWay         = new RadioButton();
            oneWay.Text    = "One-way";
            oneWay.Checked = true;
            wayGrid.Controls.Add(oneWay);
            returnWay      = new RadioButton();
            returnWay.Text = "Return";
            wayGrid.Controls.Add(returnWay);
            noDiscount         = new RadioButton();
            noDiscount.Text    = "No discount";
            noDiscount.Checked = true;
            discountGrid.Controls.Add(noDiscount);
            twentyDiscount      = new RadioButton();
            twentyDiscount.Text = "20% discount";
            discountGrid.Controls.Add(twentyDiscount);
            fortyDiscount      = new RadioButton();
            fortyDiscount.Text = "40% discount";
            discountGrid.Controls.Add(fortyDiscount);
            // Payment option
            Label paymentLabel = new Label();

            paymentLabel.Text      = "Payment by:";
            paymentLabel.Dock      = DockStyle.Fill;
            paymentLabel.TextAlign = ContentAlignment.MiddleRight;
            grid.Controls.Add(paymentLabel, 0, 2);
            payment = new ComboBox();
            payment.DropDownStyle = ComboBoxStyle.DropDownList;
            payment.Items.AddRange(new String[] { "Credit card", "Debit card", "Cash" });
            payment.SelectedIndex = 0;
            payment.Dock          = DockStyle.Fill;
            grid.Controls.Add(payment, 1, 2);
            grid.SetColumnSpan(payment, 5);
            // Pay button
            pay      = new Button();
            pay.Text = "Pay";
            pay.Dock = DockStyle.Fill;
            grid.Controls.Add(pay, 0, 3);
            grid.SetColumnSpan(pay, 6);
            // Set up event
            Prijsberekening p = new Prijsberekening();

            pay.Click += (object sender, EventArgs e) => p.DefinitievePrijs(getUIInfo());
        }