コード例 #1
0
ファイル: Form1.cs プロジェクト: JonathonRP/VisualStudio2017
        private void AddToCartButton_Click(object sender, EventArgs e)
        {
            if (AddToCartButton.Text == "Add to Cart")
            {
                if (Game[1].Checked || Game[2].Checked || Game[3].Checked)
                {
                    AddToCart();
                }
                else if (!(Game[1].Checked && Game[2].Checked && Game[3].Checked))
                {
                    MessageBox.Show("You need to pick a game", "Try Again",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    Game1.Focus();
                }
            }

            else if (AddToCartButton.Text == "Apply")
            {
                foreach (CheckBox CheckBox in Game.Values)
                {
                    if (CheckBox.Checked)
                    {
                        DiscountCalculation();
                    }
                }

                DiscountInsert.Text = $"{discount:C}";
                TotalCalculation();
                TotalInsert.Text = $"{total:C}";

                AddToCartButton.Enabled = false;
                PromoCodeText1.Enabled  = false;
                PromoCodeText2.Enabled  = false;

                foreach (ComboBox ComboBox in SubscriptionChoicesForGame.Values)
                {
                    ComboBox.SelectionLength = 0;
                }

                BuyNow.Focus();
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: JonathonRP/VisualStudio2017
        private void AddToCart()
        {
            List <string> game = new List <string>();

            for (int i = 0; i <= SubscriptionChoicesForGame.Count() + 1; i++)
            {
                game.Add(null);
            }

            for (int i = 1; i <= Game.Count; i++)
            {
                ChoiceMadeFor(Game[i], Game_Selection[i], SubscriptionChoicesForGame[i]);
            }

            Size = MaximumSize;

            foreach (CheckBox CheckBox in Game.Values)
            {
                CheckBox.Enabled = false;
            }

            foreach (Control Ctrl in Controls)
            {
                if (Ctrl is GroupBox)
                {
                    (Ctrl as GroupBox).Size = Ctrl.MinimumSize;
                }
                if (Ctrl is Button)
                {
                    (Ctrl as Button).Visible = true;
                }
            }

            foreach (ComboBox ComboBox in SubscriptionChoicesForGame.Values)
            {
                ComboBox.Size            = ComboBox.MinimumSize;
                ComboBox.Enabled         = false;
                ComboBox.SelectionLength = 0;
            }

            foreach (Control Ctrl in PromoCodeGrouping.Controls)
            {
                if (Ctrl is TextBox)
                {
                    if (Ctrl.Name == PromoCodeText2.Name)
                    {
                        (Ctrl as TextBox).Focus();
                    }
                }
            }

            for (int i = 1; i <= Game.Count; i++)
            {
                CheckOutReceiptApplying(game[i], Game_Selection[i]);
            }

            AddToCartButton.Text = "Apply";

            if (ValidPromoCode(PromoCodeText2.Text, out string errMsg))
            {
                AddToCartButton.Enabled = false;
                PromoCodeText1.Enabled  = false;
                PromoCodeText2.Enabled  = false;
                BuyNow.Focus();
            }
        }