本文介绍了问题项目WPF C#单击一下即可完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的自动贩卖机小项目做得更好.
但是现在我遇到了一些错误.

每次如果我按下硬币按钮,都将导致单击延迟.
例如,当插入的硬币达到相同/更大的汇率时,您需要再次单击它才能禁用它.

My small project of a vending Machine i going better.
But now i got a few bugs.

each time if i press the coin button it disables a click to late.
Examle when the inserted coin reach the same/Bigger rate you need to click it one more time before it disables.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Drankmaatje
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        decimal cola;
        decimal water;
        decimal koffie;
        decimal soep;
        decimal tweeEuro;
        decimal eenEuro;
        decimal vijtigCent;
        decimal twintigCent;
        decimal tienCent;
        decimal vijfCent;
        decimal keuze;
        decimal verschil;
        decimal totaal;

        public Window1()
        {
            InitializeComponent();
        }

        private void btnCola_Click(object sender, RoutedEventArgs e)
        {
            cola = 0.60M;
            keuze = cola;
            lblKeuze.Content = keuze;
            gbGeldInworp.IsEnabled = true;
            lblStatus.Content = "Betaal";

        }

        private void btnWater_Click(object sender, RoutedEventArgs e)
        {
            water = 0.50M;
            keuze = water;
            lblKeuze.Content = keuze;
            gbGeldInworp.IsEnabled = true;
            lblStatus.Content = "Betaal";


        }

        private void btnkoffie_Click(object sender, RoutedEventArgs e)
        {
            koffie = 1.50M;
            keuze = koffie;
            lblKeuze.Content = keuze;
            gbGeldInworp.IsEnabled = true;
            lblStatus.Content = "Betaal";
        }

        private void btnsoep_Click(object sender, RoutedEventArgs e)
        {
            soep = 4.50M;
            keuze = soep;
            lblKeuze.Content = keuze;
            gbGeldInworp.IsEnabled = true;
            lblStatus.Content = "Betaal";
        }

        private void btnTweeEuro_Click(object sender, RoutedEventArgs e)
        {
            btnCancel.IsEnabled = true;
            tweeEuro = 2.00M;
            if (keuze >= totaal)
                totaal = totaal + tweeEuro;
            else
                btnKoop.IsEnabled = true;
            lblTotaalInwerp.Content = totaal;
            lblStatus.Content = "Koop";

        }

        private void btnEenEuro_Click(object sender, RoutedEventArgs e)
        {
            btnCancel.IsEnabled = true;

            eenEuro = 1.00M;
            if (keuze >= totaal)
                totaal = totaal + eenEuro;
            else
                btnKoop.IsEnabled = true;
            lblTotaalInwerp.Content = totaal;
            lblStatus.Content = "Koop";


        }

        private void btnVijtigCent_Click(object sender, RoutedEventArgs e)
        {
            btnCancel.IsEnabled = true;
            vijtigCent = 0.50M;
            if (keuze >= totaal)
                totaal = totaal + vijtigCent;
            else
                btnKoop.IsEnabled = true;
            lblTotaalInwerp.Content = totaal;

            lblStatus.Content = "Koop";
        }

        private void btnTwintigCent_Click(object sender, RoutedEventArgs e)
        {
            btnCancel.IsEnabled = true;
            twintigCent = 0.20M;
            if (keuze >= totaal)
                totaal = totaal + twintigCent;
            else
                btnKoop.IsEnabled = true;
            lblTotaalInwerp.Content = totaal;
            lblStatus.Content = "Koop";
        }

        private void btnTienCent_Click(object sender, RoutedEventArgs e)
        {
            btnCancel.IsEnabled = true;
            tienCent = 0.10M;
            if (keuze >= totaal)
                totaal = totaal + tienCent;
            else
                btnKoop.IsEnabled = true;
            lblTotaalInwerp.Content = totaal;
            lblStatus.Content = "Koop";
        }

        private void btnVijfCent_Click(object sender, RoutedEventArgs e)
        {
            btnCancel.IsEnabled = true;
            vijfCent = 0.05M;

            if (keuze >= totaal)
                totaal = totaal + vijfCent;
            else
                btnKoop.IsEnabled = true;
            lblTotaalInwerp.Content = totaal;
            lblStatus.Content = "Koop";

        }

        private void btnKoop_Click(object sender, RoutedEventArgs e)
        {
            gbGeldInworp.IsEnabled = false;
            gbKeuzeDrank.IsEnabled = false;
            btnCancel.IsEnabled = false;
            btnKoop.IsEnabled = false;
            lblStatus.Content = "Neem";

            int count2E = 0;
            int count1E = 0;
            int count50C = 0;
            int count20C = 0;
            int count10C = 0;
            int count5C = 0;

            verschil = totaal - keuze;
            /* lblMelding.Content = verschil;*/


            do
            {
                if (verschil >= 2M)
                {
                    count2E++;
                    verschil = verschil - 2M;
                }

                else if (verschil >= 1M)
                {
                    count1E++;
                    verschil = verschil - 1M;
                }

                else if (verschil >= 0.50M)
                {
                    count50C++;
                    verschil = verschil - 0.50M;
                }

                else if (verschil >= 0.20M)
                {
                    count20C++;
                    verschil = verschil - 0.20M;
                }

                else if (verschil >= 0.10M)
                {
                    count10C++;
                    verschil = verschil - 0.10M;
                }

                else if (verschil >= 0.05M)
                {
                    count5C++;
                    verschil = verschil - 0.05M;
                }
                else
                {
                }

            } while (verschil != 0);
            {
                if (count2E != 0)
                listBox1.Items.Add(count2E + " x 2 Euro ");
                if (count1E != 0)
                listBox1.Items.Add(count1E + " x 1 Euro ");
                if (count50C != 0)
                listBox1.Items.Add(count50C + " x 50Cent ");
                if (count20C != 0)
                listBox1.Items.Add(count20C + " x 20Cent ");
                if (count10C != 0)
                listBox1.Items.Add(count10C + " x 10Cent ");
                if (count5C != 0)
                listBox1.Items.Add(count5C + " x 5 Cent");
                btnNeemDrank.Visibility = Visibility.Visible;







            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            gbGeldInworp.IsEnabled = false;
            btnCancel.IsEnabled = false;
            btnKoop.IsEnabled = false;
            btnNeemDrank.Visibility = Visibility.Hidden;
            lblStatus.Content = "Kies";
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            gbGeldInworp.IsEnabled = false;
            btnCancel.IsEnabled = false;
            btnKoop.IsEnabled = false;
            lblKeuze.Content = "";
            lblStatus.Content = "Kies";
            lblTotaalInwerp.Content= "";




        }

        private void btnNeemDrank_Click(object sender, RoutedEventArgs e)
        {
            gbGeldInworp.IsEnabled = false;
            gbKeuzeDrank.IsEnabled = true;
            btnCancel.IsEnabled = false;
            btnKoop.IsEnabled = false;
            lblStatus.Content = "Kies";
            lblKeuze.Content = "";
            lblTotaalInwerp.Content = "";
            btnNeemDrank.Visibility = Visibility.Hidden;
            listBox1.Items.Clear();

        }

    }
}

推荐答案


这篇关于问题项目WPF C#单击一下即可完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:38